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看到以下内容:
这可能最终适用于我的完整perl脚本,而不是这个hello world程序,但它让我觉得我应该经历安装最新版本的perl作为非root用户的痛苦. ADDENDUM2 我安装了activestate perl 5.16.3,问题以及我实际脚本的问题仍然存在. 我怀疑在这个hello world程序的情况下,我必须使用/解释valgrind不正确,但我还不明白. UPDATE1 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条评论:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |