http://qs321.pair.com?node_id=529304

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?

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.

    -xdg

    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.