in reply to Circular references and Garbage collection.

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.