简体   繁体   English

Valgrind:内存泄漏还是没有?

[英]Valgrind: Memory leak or no?

I'm running valgrind on my program and I'm getting the following output (I'm gonna omit the 83 errors above this, let me know if I should include them in the log): 我在程序上运行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)

This is the output I get from valgrind no matter how long I run my program, whether it's 2 seconds or 2 minutes. 无论我运行程序多长时间,无论是2秒还是2分钟,这都是我从valgrind获得的输出。

Since 'possibly lost' doesn't increase over time, is it safe to assume that I do not have a memory leak? 由于“可能丢失”不会随时间增加,因此可以安全地假设我没有内存泄漏吗?

The errors all seem to come from libglib and revolve around g_malloc0 and g_realloc. 这些错误似乎都来自libglib,并且围绕着g_malloc0和g_realloc。

Possibly lost errors in valgrind cover a subset of scenarios involving pointer chains. valgrind中Possibly lost错误涵盖了涉及指针链的部分情形。 I would definitely chase the cause of this down, until you can confirm it's not an issue (at the very least, your memory footprint shouldn't be growing), since it can indicate other logic problems in your code. 我肯定会追究造成这种情况的原因,直到您可以确认这不是问题为止(至少,您的内存占用不会增长),因为它可以指示代码中的其他逻辑问题。

This post has an answer that addresses it in more detail. 这篇文章的答案可以更详细地解决它。

For more information, you can also have a look at the relevant section in the valgrind manual. 有关更多信息,您也可以查看valgrind手册中的相关部分

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM