Consider the following code.
using boost::shared_ptr;
struct B;
struct A{
~A() { std::cout << \"~A\" << std::endl; }
shared_ptr
If you have circular references like this, one object should hold a weak_ptr to the other, not a shared_ptr.
From the shared_ptr introduction:
Because the implementation uses reference counting, cycles of
shared_ptrinstances will not be reclaimed. For example, ifmain()holds ashared_ptrtoA, which directly or indirectly holds ashared_ptrback toA,A's use count will be 2. Destruction of the originalshared_ptrwill leaveAdangling with a use count of 1. Useweak_ptrto "break cycles."
Thanks, Glen, for the link.