我之前使用过valgrind,它非常有帮助。我最近设置了一个开发环境并再次开始使用valgrind。这次它发现没有丢失的记忆!即使我使用CTRL-C对某些内存进行malloc然后中断,我也会获得下面的转储。有人可以解释发生了什么吗?
...困惑
==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)
答案 0 :(得分:4)
如果仍有指向malloc
内存的指针,则不是泄漏。它在摘要中显示为仍然可以访问。
不是free
ed的内存如果仍处于活动状态,则不一定会泄露,也就是说,某处(全局,堆栈或寄存器)仍有指向它的指针。