Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: undefining hashes to free memory

by tachyon (Chancellor)
on Mar 15, 2004 at 20:58 UTC ( #336834=note: print w/replies, xml ) Need Help??

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.



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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://336834]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2018-07-22 18:46 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (455 votes). Check out past polls.