in reply to Deallocating HASH pointer

For a tree, you should be fine deleting the top node (or simply letting the variable holding it go out of scope).

Since perl5 uses reference counting to know when to free the space used by variables, this strategy works fine except when you have a data structure with circular references - for example when modelling a graph, or a tree in which each node also holds a reference to the top of the tree.

In such cases extra care is needed: you can either avoid circularity using weak references, or take care to clean up enough of the references by hand to allow perl to do the rest.

Hugo

Replies are listed 'Best First'.
Re: Re: Deallocating HASH pointer
by Doraemon (Beadle) on May 11, 2004 at 12:56 UTC
    What about if the '$tree' is a static variable?
    BEGIN { $tree = {}; sub createTree { # we create big tree ... } sub deleteTree { $tree = undef; # or $tree = {}; } } createTree(); deleteTree();
    Is this also apply?