in reply to Release memory in hash of hashes

You can

undef %hash;
which will reduce it's reference count by one, and *potentially* free it's memory, provided there are no other references to the structure, or parts of it, that are still in scope.

If you are holding any other pointers to %hash or parts of it, you'll need to undef them too (provided they are still in scope but no longer useful).

Useful discussion here: Perl garbage collector and swap and there was a recent thread on memory de-allocation here : Memory reusability and the google book link to the internals discussion in Advanced Perl Programming.

Although, the beauty of Perl is that you shouldn't have to worry about these sort of things! HTH

Update: Added google book link

Just a something something...

Replies are listed 'Best First'.
Re^2: Release memory in hash of hashes
by ikegami (Patriarch) on Aug 17, 2009 at 15:47 UTC

    You can undef %hash which will reduce it's reference count by one

    If "it" refers to the hash %hash, you're wrong.

    • %hash = (); empties the buckets, reducing the reference counts of all elements by one.

    • undef %hash; empties and frees the buckets, reducing the reference counts of all elements by one.

    However, neither lowers the reference count of %hash. (They could lower the reference count indirectly if you had something like $hash{ele} = \%hash;, but that's not what you said.)

    The later is usually overkill.

      That is what i took the OP to mean. I assumed they would never use the %hash again and wanted to totally flush it and the buckets, not just empty it. Overkill maybe...

      Just a something something...