I am using valgrind for the first time in linux 当我运行我的可执行文件时,我得到以下消息。
==31440==
==31440== FILE DESCRIPTORS: 3 open at exit.
==31440== Open file descriptor 2: /dev/pts/9
==31440== <inherited from parent>
==31440==
==31440== Open file descriptor 1: /dev/pts/9
==31440== <inherited from parent>
==31440==
==31440== Open file descriptor 0: /dev/pts/9
==31440== <inherited from parent>
==31440==
==31440==
==31440== HEAP SUMMARY:
==31440== in use at exit: 72,704 bytes in 1 blocks
==31440== total heap usage: 40 allocs, 39 frees, 91,192 bytes allocated
==31440==
==31440== 72,704 bytes in 1 blocks are still reachable in loss record 1 of 1
==31440== at 0x4C277AB: malloc (in
/usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==31440== by 0x4EC3AAF: _GLOBAL__sub_I_eh_alloc.cc (eh_alloc.cc:117)
==31440== by 0x400E859: call_init.part.0 (in /lib64/ld-2.18.so)
==31440== by 0x400E942: _dl_init (in /lib64/ld-2.18.so)
==31440== by 0x40011C9: ??? (in /lib64/ld-2.18.so)
==31440==
==31440== LEAK SUMMARY:
==31440== definitely lost: 0 bytes in 0 blocks
==31440== indirectly lost: 0 bytes in 0 blocks
==31440== possibly lost: 0 bytes in 0 blocks
==31440== still reachable: 72,704 bytes in 1 blocks
==31440== suppressed: 0 bytes in 0 blocks
==31440==
==31440== For counts of detected and suppressed errors, rerun with: -v
==31440== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)这是否意味着我有内存泄漏?如何知道是否存在内存泄漏。你们中的任何人可以推荐我如何使用valgrind和解释错误的链接。提前谢谢。
发布于 2016-07-22 22:42:21
首先,如果你有泄漏,例如在C中,这意味着你做了一个malloc,但你没有释放它。有关详细信息,请使用man malloc和man free。
我可以给你一个提示,当你启动Valgrind时,你可以使用参数--leak-check=full,它会告诉你你没有释放哪个malloc。
例如:
$>valgrind --leak-check=full ./foo.发布于 2015-10-08 23:05:42
如果你的程序有内存泄漏,它将在泄漏摘要中指定有多少行有内存泄漏。
definitely lost: x bytes in 0 blocks
indirectly lost: y bytes in 0 blocks你可以通过创建一个"class obj = new class()“来运行一个快速测试,而不删除obj,这肯定会在你的项目中造成内存泄漏。
https://stackoverflow.com/questions/32927563
复制相似问题