10

I've run Devel::Leak in my program and I don't understand the output it's giving me.

To start, I see it's printing a list of pointers. Can I get that list in an array? Then I can use FindRef to see where it's coming from.

For example:

new 0xaebc28 : SV = PVGV(0x30e7e48) at 0xaebc28
  REFCNT = 1
  FLAGS = (GMG,SMG)
  IV = 0
  NV = 0
  PV = 0
  MAGIC = 0x2db7dc0
    MG_VIRTUAL = &PL_vtbl_glob
    MG_TYPE = PERL_MAGIC_glob(*)
    MG_OBJ = 0xaebc28
  NAME = "SUPER::"
  NAMELEN = 7
  GvSTASH = 0x76b228    "IO::File"
  GP = 0x314b170
    SV = 0x30283c8
    REFCNT = 1
    IO = 0x0
    FORM = 0x0  
    AV = 0x0
    HV = 0x301fdb8
    CV = 0x0
    CVGEN = 0x0
    GPFLAGS = 0x0
    LINE = 161
    FILE = "/mypath/perl_install/perl/lib/5.8.9/x86_64-linux/IO/File.pm"
    FLAGS = 0x0
    EGV = 0xaebc28      "SUPER::"

or a bunch of smaller entries:

new 0x161c268 : SV = RV(0x3029b40) at 0x161c268
  REFCNT = 1
  FLAGS = (ROK)
  RV = 0x161c218

What do I do with this? I get the Perl struct stuff (magic, iv, pv,..), but how do I go from these lines to knowing where my leak is occurring?

Borodin
  • 126,100
  • 9
  • 70
  • 144
mmccoo
  • 8,386
  • 5
  • 41
  • 60
  • 1
    http://blog.woobling.org/2009/05/become-hero-plumber.html; see also http://stackoverflow.com/questions/1359771/perl-memory-usage-profiling-and-leak-detection, http://stackoverflow.com/questions/2223721/common-perl-memory-reference-leak-patterns, http://stackoverflow.com/questions/1663498/finding-a-perl-memory-leak, http://stackoverflow.com/questions/295385/are-there-any-tools-for-finding-memory-leaks-in-my-perl-program – Ether Aug 24 '10 at 18:59
  • @Ether Thanks for the link. Mostly I'm looking to identify what these leaked objects are more than why they're not being collected. – mmccoo Aug 24 '10 at 20:11

1 Answers1

1

Take a look at Devel::LeakTrace for a module which also records where memory has been allocated.

vladr
  • 65,483
  • 18
  • 129
  • 130
  • sadly, Devel::LeakTrace needs GLib 1.2 (latest is 2.4) and hasn't been updated since 2003. Looks interesting though. – Philip Potter Aug 28 '10 at 11:00
  • so I got Devel::LeakTrace to build using the Build.PL here: https://rt.cpan.org/Public/Bug/Display.html?id=59027 but it's telling me that `perl -MDevel::LeakTrace -e '{my $f = [1,2,3]; undef $f'}` leaks 4 SVs! That can't be right can it? – Philip Potter Aug 28 '10 at 11:34
  • @philip, also check out http://search.cpan.org/~gfuji/Test-LeakTrace-0.13/, it's more recent. – vladr Aug 30 '10 at 20:55
  • thanks I will look at that. I also see [Devel::LeakTrace::Fast](http://search.cpan.org/perldoc/Devel::LeakTrace::Fast) might be worth a look. – Philip Potter Aug 30 '10 at 21:03
  • Test::LeakTrace uses Devel::Leak for its leak dumps, so this won't help trying to interpret the output. – SineSwiper Oct 30 '12 at 14:00
  • @BrendanByrd, both `Devel::LeakTrace` and the much more recent `Test::LeakTrace` record the allocation sites (see `runops_leakcheck` in `LeakTrace.xs`), which is exactly what the OP requested at the bottom of his post. I'm not sure I understand your objection. – vladr Nov 04 '12 at 07:27