我以前用过valgrind,它很有帮助。我最近设置了一个开发环境并再次开始使用valgrind。这次它找不到丢失的记忆!即使我malloc一些内存,然后用CTRL-C中断程序,我也会得到下面的转储文件。有人能解释一下发生了什么事吗?
困惑的。。。。

==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)

最佳答案

如果仍有指向malloced内存的指针,则不是泄漏。它在摘要中显示为仍然可以访问。
freeed的内存如果仍然存在,也就是说,在某个地方(全局、堆栈或寄存器)仍然有指向它的指针,则不一定会泄漏

10-08 12:05