Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: tracking down a memory leak in $_

by perrin (Chancellor)
on Jul 20, 2006 at 13:52 UTC ( #562583=note: print w/replies, xml ) Need Help??

in reply to tracking down a memory leak in $_

If what you mean is that your program grows over time, that doesn't indicate a memory leak. A leak is when memory is allocated and then becomes unaccessible and is never used again. Chances are, your program is growing because it needs the memory for something you're doing.

For advice on how to avoid using too much memory with Perl, see the mod_perl book.

Replies are listed 'Best First'.
Re^2: tracking down a memory leak in $_
by edan (Curate) on Jul 20, 2006 at 19:09 UTC
    Well... if I run the exact same code over and over again in a loop, I might expect it to grow the first few times as various things are allocated, but if it consistently continues to grow after executing the same code after dozens and hundreds of loops, I consider that a leak. I don't care if perl is holding a pointer to it somewhere in its bowels - if it keeps allocating more memory in each loop, it's a leak in my book...

    As I said, I'm pretty sure that it's $_ that's growing. I don't see anything that's obviously requiring more and more space in $_. So isn't that a leak?

    I really wish I could boil it down to a simple test case, but I'm still puzzled as to exactly what aspect of the code is causing the leak...


      If the data that you put in $_ or any other variable becomes larger at some point, then the memory grows, and it stays larger. The memory will get reused for that variable, but it won't be returned.

      One thing that often bites people is that reading a nested hash can create hash keys and use more memory. For example:

      If there was no baz key before, there is now, and that takes some space.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://562583]
and the universe expands...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-06-24 02:11 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.