gpt4 book ai didi

c - valgrind 没有捕捉到明显丢失的内存

转载 作者:太空宇宙 更新时间:2023-11-04 06:40:32 26 4
gpt4 key购买 nike

我以前使用过 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 的内存如果仍然存在则不一定泄漏,也就是说,在某处仍然有指向它的指针(全局地,来自堆栈或来自寄存器。)

关于c - valgrind 没有捕捉到明显丢失的内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9037268/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com