简体   繁体   English

在我的Perl程序中是否有任何查找内存泄漏的工具?

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

I am using ActiveState Perl 5.6 on a Windows 2003 Server, and am having some memory leak issues. 我在Windows 2003 Server上使用ActiveState Perl 5.6,并且遇到了一些内存泄漏问题。 Are there any good tools (or even bad tools which would give a clue) which I would be able to use to help find them. 是否有任何好的工具(甚至可以提供线索的坏工具),我可以使用它来帮助找到它们。

All perl program memory leaks will either be an XS holding onto a reference, or a circular data structure. 所有perl程序内存泄漏都将是保存在引用上的XS,或者是循环数据结构。 Devel::Cycle is a great tool for finding circular references, if you know what structures are likely to contain the loops. 如果您知道哪些结构可能包含循环,则Devel :: Cycle是查找循环引用的绝佳工具。 Devel::Peek can be used to find objects with a higher-than-expected reference count. Devel :: Peek可用于查找引用计数高于预期的对象。

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. 如果你不知道在哪里看, Devel :: LeakTrace :: Fast可能是一个很好的第一名,但是你需要一个用于调试的perl。

If you suspect the leak is inside XS-space, it's much harder, and Valgrind will probably be your best bet. 如果你怀疑泄漏是在XS空间内,那就更难了, Valgrind可能是你最好的选择。 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. Test :: Valgrind可以帮助您减少搜索所需的代码量,但这不适用于Windows,因此您必须将(至少泄漏部分)移植到Linux才能执行此操作。

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. Devel :: Gladiator将向您显示Perl在任何给定时间内存在的每个变量类型的数量,以及它们引用的内容。 Very useful for figuring out what type of objects are being created but not freed. 对于确定正在创建但未释放的对象类型非常有用。

Since it's not been mentioned yet, Devel::Size will report the size of a data structure. 由于尚未提及, Devel :: Size将报告数据结构的大小。 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. Devel :: SizeMe是我的一个业余爱好项目,旨在解决Devel :: Size的问题,并实现perl解释器的整个内存使用的可视化。 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. 除了其他评论,您可能会发现我在LPW2013上的Perl Memory Use演讲很有用。 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. 我还建议看一下我在演讲中提到的Paul Evans Devel :: MAT模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM