Perl Memory Usage
| |
| The Bush Survival Guide - 250 Ways to Make It Through The NExt Four Years Without Misunderestimating the Dangers Ahead, and Other Subliminable Stategeries |
|
Links:
| |
Subjects > Computers > Software > Computer Programming > Perl?Create
I run into this problem a lot also.
Perl is known to use memory at a great rate. I saw some posts that said figure out how much memory a reasonable program would use, and then multiply by three to estimate Perl's memory usage. Amazingly there is very little advice on the net about memory efficiency in perl. It is astounding to me that there is not some kind of function to tell how much total memory the perl interpreter has allocated. How difficult could it be to keep a counter that is added to when memory is allocated, and substracted from when memory is freed? Even better would be deeper functions to let you see the reference count of an object, or maybe even walk the object chain (if there is one) and show object still remaining in memory.
One thing I've noticed is that when deleting a hash element that contains a hash, it seems like the inner hash does not get freed. And I've discovered it appears to help to walk through the elements of a hash deleting each one in turn, and to make nested walk throughs if the has contains nested hashes of hashes.
Also, it is probably better to use delete on each element, than to use undef. Using undef just sets that key of the hash to be "undef", deleting it deletes the item and the key from the hash. However, I am not sure if it is a good idea to be doing a delete on declared elements within a pseudohash.
Another possible work around is to structure your program so it does small discrete units of work, then if you have a lots of separate tasks for it to do, start a fresh copy of the program for each task. For example, a perl program operating on records in an address book might restart after every 100 records are processed. This is a drastic solution to the problem of leaked memory, and it's practicality depends on the amount of information you need to maintain between the execution of discrete tasks.
See also Garnet's Interesting Articles
Check out [Facts About Trees]
|
Interested in Anne Heche?