Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

How to locate a memory leak..

by Eyck (Priest)
on Feb 10, 2006 at 08:19 UTC ( #529304=perlquestion: print w/ replies, xml ) Need Help??
Eyck has asked for the wisdom of the Perl Monks concerning the following question:

Esteemed monks,

I've got a little app...and after few weeks of usage I noticed that one of instances grows to ~50M, since fresh, few-hours old instance usually report ~10M usage, I might be having a leak.

The only datastructures I use are about 10 hashes, they don't grow, and an array for logs, but that gets cleaned every now and then... that would suggest the problem with one with libraries...

How would I go about locating it?

Comment on How to locate a memory leak..
Replies are listed 'Best First'.
Re: How to locate a memory leak..
by tirwhan (Abbot) on Feb 10, 2006 at 08:31 UTC
Re: How to locate a memory leak..
by xdg (Monsignor) on Feb 10, 2006 at 12:25 UTC

    I believe that someone once told me that the memory dedicated to an array doesn't shrink, even if you assign an empty list to it -- rather Perl just adjusts its pointers for the start and end of the array, but the memory stays allocated. Could that be causing the problem?

    You might try using a new lexical array or array reference instead of "cleaning" the array and see if that helps.

    P.S. That's true for hashes as well -- while the memory for the keys and values can be cleared, the memory allocated to the underlying array stays allocated. I think that jdhedden told me that when we were discussing hash-based vs array-based inside-out objects.


    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: How to locate a memory leak..
by perrin (Chancellor) on Feb 10, 2006 at 20:53 UTC
    Once you load something into memory, the memory will remain allocated. The array is most likely the problem here. Try to load less at one time, reading the file in chunks.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://529304]
Approved by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2015-10-09 13:11 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (242 votes), past polls