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

In reply to Re: Re: How Far Can I Nest? by theorbtwo
in thread How Far Can I Nest? by Cody Pendant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.