shared_ptr memory leaks ex

This commit is contained in:
Kolan Sh 2012-11-13 11:50:33 +04:00
parent 7b1fcf28ae
commit 2a7ae317e3
1 changed files with 28 additions and 0 deletions

28
cpp/shared_ptr/main.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <boost/smart_ptr.hpp>
class Foo {
public:
boost::shared_ptr<Foo> s_ptr;
boost::weak_ptr<Foo> w_ptr;
Foo ()
{
std::cout << "Foo (): allocate big piece by " << this << std::endl;
}
~Foo ()
{
std::cout << "~Foo (): deallocate the piece by " << this << std::endl;
}
};
int main (int argc, char *argv[])
{
boost::shared_ptr<Foo> foo (new Foo);
if (1 < argc ? argv[1][0] - '0' : 0)
foo->s_ptr = boost::shared_ptr<Foo> (foo);
else
foo->w_ptr = boost::weak_ptr<Foo> (foo);
return 0;
}