9 Sep
2011
9 Sep
'11
6:44 a.m.
I think that it is expected that shared_ptr cannot handle points that have cyclic references. In the following example, "a" points to "b" and "b" points to "a". There is a memory leak. I then modified it to remove the dependence using bare pointers, then the leak is resolved. But this is not a very satisfactory solution, as the programmer has to know whether to use bare point or shared_ptr. For very complexity program, it may not be possible to figure out it correctly.
Does anybody know what is the best strategy for handing cyclic pointers?
On of the directions should use weak_ptr.