
Larry Evans wrote:
Hi Peter,
The code here:
http://lists.boost.org/boost-users/2005/05/11805.php
appears to require the user to specify the root pointers in order to do a complete collection. This is in contrast to sp_collect.cpp which used Christopher's method [chri84] cited here:
http://www.cs.kent.ac.uk/people/staff/rej/gcbib/gcbibC.html
to find the roots, at least AFAICT. Is this intentional, ...
Yes, this is intentional, as reset_and_collect does not require any help from the implementation of shared_ptr, so it can be used with tr1::shared_ptr as well. It has been developed in response to Eric Niebler's scenario where the roots that form cycles are known to the programmer. (He ended up not using it, though :-) ) It's possible to combine the two approaches and perhaps provide a default enable_tracking that does a memory scan as in sp_collector. I think that in most typical cyclic shared_ptr situations the problematic roots are known in advance, though, so a reset_and_collect-type solution may be enough. Note that reset_and_collect is perfectly capable of figuring out on its own that unknown roots to a node exist, it only needs a starting point (and can be modified to work with several starting points).