我在我的程序上运行 valgrind 并得到以下输出(我将忽略上面的 83 个错误,如果我应该将它们包含在日志中请告诉我):
==9723== LEAK SUMMARY:
==9723== definitely lost: 0 bytes in 0 blocks
==9723== indirectly lost: 0 bytes in 0 blocks
==9723== possibly lost: 4,676 bytes in 83 blocks
==9723== still reachable: 88,524 bytes in 579 blocks
==9723== suppressed: 0 bytes in 0 blocks
==9723== Reachable blocks (those to which a pointer was found) are not shown.
==9723== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==9723==
==9723== For counts of detected and suppressed errors, rerun with: -v
==9723== ERROR SUMMARY: 83 errors from 83 contexts (suppressed: 3 from 3)
无论我运行程序多长时间,无论是 2 秒还是 2 分钟,这都是我从 valgrind 获得的输出。
由于“可能丢失”不会随着时间的推移而增加,是否可以安全地假设我没有内存泄漏?
这些错误似乎都来自 libglib,并围绕着 g_malloc0 和 g_realloc。
最佳答案
valgrind 中的
Possibly lost
错误涵盖了涉及指针链的场景子集。我肯定会追查造成这种情况的原因,直到您确认这不是问题(至少,您的内存占用量不应增加),因为它可能表明您的代码中存在其他逻辑问题。
This帖子有一个更详细地解决它的答案。
有关更多信息,您还可以查看 relevant section在 valgrind 手册中。
关于c - Valgrind:是否有内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20848754/