#include class Foo { public: boost::shared_ptr s_ptr; boost::weak_ptr 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 (new Foo); if (1 < argc ? argv[1][0] - '0' : 0) foo->s_ptr = boost::shared_ptr (foo); else foo->w_ptr = boost::weak_ptr (foo); return 0; }