in reply to undefining hashes to free memory

In addition to the above you can't always rely on Perl to do the right thing with regards to memory return. In our experience perl never really gives back memory to the OS until absolutely forced to. This is referred to as lazy garbage collection by p5p and semi-non-existent garbage collection by some more cynical punters. Also undeffing large hashes can take a very long time on some systems due to a known malloc bug. You may find value in effectively making the reused hashes global in some circumstances:

my %hash; ... sub process { %hash = (); # empty hash but not using undef # do stuff with hash }

As always YMMV.

cheers

tachyon

Replies are listed 'Best First'.
Re: Re: undefining hashes to free memory
by Anonymous Monk on Mar 15, 2004 at 21:48 UTC
    Thanks for clarification. As far as giving memory back to the OS, I don't think it's unreasonable not to, but I also think it's reasonable to expect efficient reuse of memory from out of scope variables, maybe that's too much to expect ;) I did test your approach before I posted and it seemed to work but is a little messy in my situtation, I also know about the malloc bug and it doesn't seem to be an issue on my systems, but thanks for the informative response.

    tigervamp