Perl v5.10.1是否有内存泄漏或如何解释valgrind

前端之家收集整理的这篇文章主要介绍了Perl v5.10.1是否有内存泄漏或如何解释valgrind前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个内存泄漏的脚本.我相信这是因为我在嵌套对象上执行undef后,脚本中的内存量不变.我使用 Devel::Cycle来定位任何循环引用,并且我已经将这些循环引用转换为Scalar :: Util的弱引用.问题仍然存在.

现在我试图用Valgrind来解决这个问题.作为valgrind的第一个开始,我测试了一个perl hello world程序:

#! /usr/bin/perl

use strict;
use warnings;

print "Hello world!\n";

这是运行valgrind时的valgrind输出–​​trace-children = yes perl ./hello_world.pl:

==12823== HEAP SUMMARY:
==12823==     in use at exit: 290,774 bytes in 2,372 blocks
==12823==   total heap usage: 5,159 allocs,2,787 frees,478,873 bytes allocated
==12823==
==12823== LEAK SUMMARY:
==12823==    definitely lost: 13,981 bytes in 18 blocks
==12823==    indirectly lost: 276,793 bytes in 2,354 blocks
==12823==      possibly lost: 0 bytes in 0 blocks
==12823==    still reachable: 0 bytes in 0 blocks
==12823==         suppressed: 0 bytes in 0 blocks
==12823== Rerun with --leak-check=full to see details of leaked memory
==12823==
==12823== For counts of detected and suppressed errors,rerun with: -v
==12823== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

here开始,我的理解是,当alloc的数量不等于你有内存泄漏的自由数量时.

因为我正在做的就是打印你好世界,我不得不问这个问题,Perl解释器本身,这里是v5.10.1,至少有自己的内存泄漏,还是我解释的都是错的?

在我解决实际的perl脚本之前,我想了解这一点.

附录

我在Perl 5.12.0 delta看到以下内容

A weak reference to a hash would leak. This was affecting DBI [RT #56908].

这可能最终适用于我的完整perl脚本,而不是这个hello world程序,但它让我觉得我应该经历安装最新版本的perl作为非root用户的痛苦.

ADDENDUM2

我安装了activestate perl 5.16.3,问题以及我实际脚本的问题仍然存在.

我怀疑在这个hello world程序的情况下,我必须使用/解释valgrind不正确,但我还不明白.

UPDATE1
达西姆的答案确实有所作为.当我在perl脚本中引入以下行时:

use Perl::Destruct::Level level => 1;

然后valgrind输出是:

==29719== HEAP SUMMARY:
==29719==     in use at exit: 1,617 bytes in 6 blocks
==29719==   total heap usage: 6,499 allocs,6,493 frees,585,389 bytes allocated
==29719==
==29719== LEAK SUMMARY:
==29719==    definitely lost: 0 bytes in 0 blocks
==29719==    indirectly lost: 0 bytes in 0 blocks
==29719==      possibly lost: 0 bytes in 0 blocks
==29719==    still reachable: 1,617 bytes in 6 blocks
==29719==         suppressed: 0 bytes in 0 blocks
==29719== Rerun with --leak-check=full to see details of leaked memory
==29719==
==29719== For counts of detected and suppressed errors,rerun with: -v
==29719== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

这是一个实质性的差异.我自己的内存泄漏问题仍然存在,但至少这个hello world程序现在对valgrind来说似乎是明智的.

这整个问题虽然引出了一个问题,但是如果在程序退出之前没有释放内存,那么使用Scalar :: Util停止硬循环引用有什么意义呢,禁止使用这个有点深奥的Perl :: Destruct :: Level模块???

解决方法

泄漏是故意的. vincent in #p5p评论

Allocated memory isn’t actually released unless 07001 is set because it’s faster to let the operating system handle this. PERL_DESTRUCT_LEVEL is only available for debugging builds or by using 07002 from perl.

猜你在找的Perl相关文章