Are there any tools for finding memory leaks in my Perl program?

后端 未结 3 917
抹茶落季
抹茶落季 2020-12-05 08:43

I am using ActiveState Perl 5.6 on a Windows 2003 Server, and am having some memory leak issues. Are there any good tools (or even bad tools which would give a clue) which

相关标签:
3条回答
  • 2020-12-05 09:26

    Since it's not been mentioned yet, Devel::Size will report the size of a data structure. There's no other information given and the rules it uses to determine the 'boundary' of your data structure are opaque. For simple structures this isn't a problem.

    Devel::SizeMe is a hobby project of mine that aims to resolve the problems of Devel::Size and enable visualization of the entire memory usage of a perl interpreter. See my blog for extra information, including links to screencasts and videos. One of my goals is to enable detection and visualization of leaks, but that's still a way off yet.

    Updates:

    In addition to the other comments, you may find my Perl Memory Use talk at LPW2013 useful. I'd recommend watching the screencast as it explains the slides and has some cute visuals and some Q&A at the end.

    I'd also suggest looking at Paul Evans Devel::MAT module which I mention in the talk.

    0 讨论(0)
  • 2020-12-05 09:28

    Devel::Gladiator will show you a list of how many of each variable type Perl has in memory at any given time, and what they are references to. Very useful for figuring out what type of objects are being created but not freed.

    0 讨论(0)
  • 2020-12-05 09:29

    All perl program memory leaks will either be an XS holding onto a reference, or a circular data structure. Devel::Cycle is a great tool for finding circular references, if you know what structures are likely to contain the loops. Devel::Peek can be used to find objects with a higher-than-expected reference count.

    If you don't know where else to look, Devel::LeakTrace::Fast could be a good first place, but you'll need a perl built for debugging.

    If you suspect the leak is inside XS-space, it's much harder, and Valgrind will probably be your best bet. Test::Valgrind may help you lower the amount of code you need to search, but this won't work on Windows, so you'd have to port (at least the leaky portion) to Linux in order to do this.

    0 讨论(0)
提交回复
热议问题