in reply to Re: How Far Can I Nest?
in thread How Far Can I Nest?
In general, there are two methods to deal with circular references. They are DESTROY and weak refs.
With DESTROY, you can explicity undef the references that you think might be circular. The advantage is that there is rarely a problem with undefing a reference that you no longer need. The problem is that most data-structures don't get a destroy, only objects (things that have at least one blessed ref to them, that is).
The other method is weak refs. This is a fairly new feature (5.6, IIRC). That's one problem right off the back. The idea of weak references is that they don't count as a reference to the refcounting system, so a circular reference isn't a problem if one of it's links is weak; it can be broken by the garbage-collection system. (Nit alert: refcounting might not technicaly count as GC.)
Using weak references does imply a more closely inspected data structure. If you use too many weak references, you run the risk of your data dissapearing because the ref count went to 0 because there were no nonweak references.
OTOH, weak references seem less klugy to me, and have the advantage of not requiring a "controling" object to have the DESTROYer. (Nit warning: yes, destructor is the normal term, and proper English. OTOH, it doesn't contain the substring DESTROY, which I wanted, since it is the name of the function/method.)
TACCTGTTTGAGTGTAACAATCATTCGCTCGGTGTATCCATCTTTG ACACAATGAATCTTTGACTCGAACAATCGTTCGGTCGCTCCGACGC
|
|---|