There's generaly three ways to get around this: Don't use circular refs, break them yourself (BTW, it's more clear to say $ref=undef or undef $ref then $ref=15), or use what is called a "weak reference", which is a referance that does not increase the refcount of a variable (BTW, variables, not blocks, have refcounts. (Except for coderefs, which in some ways /are/ variables.) Read WeakRef for details on using weak references.

Perl6 is slated, BTW, to have a more advanced GC system. This will be faster, and not have problems with circular refs, but will have it's on problems. Currently, destructors (IE DESTROY methods) are run as soon as possible after the variable has gone out of scope/become unreferancable. Under most forms of GC, this will become delayed until the next dead-object-detection run, so there will often be a delay. While this isn't important for the majority of objects, it does become imporant for things like file locks and transactions, where you want the live time to be as short as possible.

BTW, I'm no internals wizard. Take this all with a CC or so of salt.


Confession: It does an Immortal Body good.


In reply to Re: Circular references and Garbage collection. by theorbtwo
in thread Circular references and Garbage collection. by DigitalKitty

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.