On Sat, Sep 6, 2008 at 21:48, MGE
So I am trying to manually break the cycle at deletion. I would be grateful if somebody could take a look at the code below, which illustrates my basic approach. Assuming that I stringently break all cycles when a Child class or Parent class goes out of scope, would this approach avoid memory leaks? Would it be possible to put code into the destructor of Parent and Child classes that automatically sets the shared pointer owned by the class to null (not using the reset() function but by using the method below) hence guaranteeing that cycles are broken at deletion?
You probably don't want to assign them to a new shared_ptr, since the allocation is spurious. This is sufficient in the example: // later, manually break the cycle child->myParent.reset(); In your real case, you may need to reset others, of course. HTH, ~ Scott