in reply to Re: Can we determine when the garbage collector works?
in thread Can we determine when the garbage collector works?

Since we can't reclaim automatically the memory in closure, is that mean i still need to traverse down (i wonder why not up? :)) the tree?
  • Comment on Re: Re: Can we determine when the garbage collector works?

Replies are listed 'Best First'.
Re: Re: Re: Can we determine when the garbage collector works?
by Corion (Patriarch) on May 12, 2004 at 15:30 UTC

    First, a very simple example of a closure:

    { my $tree; sub get_tree { return $tree; }; };

    In the above example, $tree and all memory referenced by it will never go out of scope, and since $tree is invisible outside of its containing block, there is no way to free up the referenced memory.

    { my $tree; sub get_tree { return $tree; }; sub release_tree { undef $tree; }; };

    In this example, it is possible to release the memory structure referenced by $tree by calling release_tree, because it also sees the $tree variable. But this release is not automatic and thus must be done by the programmer when the time has come.