[Pdx-pm] Recommendations for memory leak checking?

Marvin Humphrey marvin at rectangular.com
Wed Jul 4 08:24:23 PDT 2007


On Jul 3, 2007, at 11:21 PM, Kevin Scaldeferri wrote:

> 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.)

Yeah, and Valgrind won't help here.  I use it for debugging XS all  
the time (perlhack has the gory details). Unfortunately, it looks  
like Perl (or at least, a debugging perl with the environment  
variable PERL_DESTRUCT_LEVEL set to 2) cleans up native circular refs  
before exiting, as illustrated below.

Marvin Humphrey
Rectangular Research
http://www.rectangular.com/


[marvin at wembly devel]$ cat circular.pl
my ( %foo, %bar );
$foo{bar} = \%bar;
$bar{foo} = \%foo;
[marvin at wembly devel]$ printenv | ack DESTRUCT
PERL_DESTRUCT_LEVEL=2
[marvin at wembly devel]$ valgrind --leak-check=full --show- 
reachable=yes --suppressions=p588_valgrind.supp /usr/local/debugperl/ 
bin/perl5.8.8 circular.pl
==25794== Memcheck, a memory error detector.
==25794== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et  
al.
==25794== Using LibVEX rev 1471, a library for dynamic binary  
translation.
==25794== Copyright (C) 2004-2005, and GNU GPL'd, by OpenWorks LLP.
==25794== Using valgrind-3.1.0, a dynamic binary instrumentation  
framework.
==25794== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et  
al.
==25794== For more details, rerun with: -v
==25794==
==25794==
==25794== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 21  
from 1)
==25794== malloc/free: in use at exit: 127 bytes in 16 blocks.
==25794== malloc/free: 688 allocs, 672 frees, 84,133 bytes allocated.
==25794== For counts of detected errors, rerun with: -v
==25794== searching for pointers to 16 not-freed blocks.
==25794== checked 288,332 bytes.
==25794==
==25794== LEAK SUMMARY:
==25794==    definitely lost: 0 bytes in 0 blocks.
==25794==      possibly lost: 0 bytes in 0 blocks.
==25794==    still reachable: 0 bytes in 0 blocks.
==25794==         suppressed: 127 bytes in 16 blocks.
[marvin at wembly devel]$








More information about the Pdx-pm-list mailing list