[Pdx-pm] Recommendations for memory leak checking?

Kevin Scaldeferri kevin at scaldeferri.com
Tue Jul 3 23:21:26 PDT 2007

On Jul 3, 2007, at 3:03 PM, Eric Wilhelm wrote:

> # from Michael G Schwern
> # on Tuesday 03 July 2007 01:52 pm:
>>> HARNESS_PERL_SWITCHES="-MDevel::Cover" make test
>>> I would like to do the same to check for memory leaks.
>> Test::Memory::Cycle can check individual objects and references for
>> memory leaks.
>> Otherwise there's Devel::Leak which I've never really had luck with.

Both of those require modifying your code, which I can't do for this  

> I also see Devel::LeakTrace.

That looks like what I want.  I'm not sure how I missed it when  
searching CPAN myself (I found the previous two suggestions).  I'll  
give it a try on Thurs and see if it seems to work for me.

(Aside: the last time I went down more-or-less this road, a couple  
years ago, I found that none of the leak checking modules really  
seemed to work all that well, or be that useful in practice.  I'm  
hoping this situation has improved.  I guess it's a function of the  
fact that it's significantly harder to leak memory in Perl than in C  
that C has excellent tools like valgrind for detecting and debugging  
memory leaks, while in Perl the situation is pretty grim.)

> Possibly something that just makes noise during global cleanup?  Here
> I'm thinking mainly about lexicals (I believe any globals have to be
> cleaned-up at the end and I guess their leakage doesn't matter anyway,
> right?)
>   BEGIN {do {"./t/this.t"}; }
>   END { print STDERR ">>>THIS IS THE END<<<\n";}
>     print STDERR "$_[0] is leaky\n";
>   };

I think that would only detect leaks of objects, right?  I'd like to  
detect leaks of normal variables as well.


PS: to those who suggested articles about coding techniques for  
avoiding leaks, I appreciate the pointers, but it's not immediately  
relevant to me.  I'm working on platform / infrastructure stuff at  
the moment -- augmenting our standard makefiles to do things like  
coverage analysis and memory analysis via make targets.

More information about the Pdx-pm-list mailing list