0
我以前使用valgrind,它一直很有帮助。我最近设置了一个开发环境并重新开始使用valgrind。这一次它发现没有失去记忆!即使我malloc一些内存,然后用CTRL-C中断程序,我得到下面的转储。有人可以解释发生了什么吗?valgrind没有捕捉到明显的丢失内存
困惑....
==2489== HEAP SUMMARY:
==2489== in use at exit: 314,145 bytes in 585 blocks
==2489== total heap usage: 1,410 allocs, 825 frees, 2,025,829 bytes allocated
==2489==
==2489== LEAK SUMMARY:
==2489== definitely lost: 0 bytes in 0 blocks
==2489== indirectly lost: 0 bytes in 0 blocks
==2489== possibly lost: 0 bytes in 0 blocks
==2489== still reachable: 314,145 bytes in 585 blocks
==2489== suppressed: 0 bytes in 0 blocks
==2489== Reachable blocks (those to which a pointer was found) are not shown.
==2489== To see them, rerun with: --leak-check=full --show-reachable=yes
==2489==
==2489== For counts of detected and suppressed errors, rerun with: -v
==2489== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 6 from 6)
记忆不丢失,如果程序终止,你仍然有一个指针。它显示在“仍然可以访问”下,因为它在程序结束时仍然可以访问。 – 2012-01-27 17:12:54
ctrl + c发送一个SIGINT,它基本上会中断您的程序继续执行。这就是为什么你得到“仍然可以访问”,因为所有的内存已被分配,但没有释放。如果你使用valgrind建议的标志,主要是'--show-reachable = yes',那么它会给出位置。 – BlackJack 2012-01-27 17:15:35
@BlackJack:请作为答案,我会upvote它,这解释它比任何已经存在的更好。 – 2012-01-27 17:26:46