Subject: | Controlling recursion - a proposal |
[Ignoring the current interface for now]
I'd like to propose this logic (in rough perlish pseudo-code) for deciding whether to chase a
pointer to a refcounted thing:
if (refcnt($thing) == 1) {
return 1; # chase
}
if (++$pointer_refs_seen{address_of($thing)} == refcnt($thing)) {
delete $pointer_refs_seen{address_of($thing)};
return 1; # chase
}
return 0; # don't chase
So:
* everything obviously owned directly will be followed without question.
* everything else gets a 'visit count' incremented.
* if the visit count has reached the ref count then we can chase the pointer.