Valgrind:内存泄漏还是没有? [英] Valgrind: Memory leak or no?

查看:164
本文介绍了Valgrind:内存泄漏还是没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在程序上运行valgrind,并且得到以下输出(我将忽略上面的83个错误,让我知道是否应将它们包括在日志中):

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

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

这是我从valgrind获得的输出,无论我运行程序多长时间,无论是2秒还是2分钟.

This is the output I get from valgrind no matter how long I run my program, whether it's 2 seconds or 2 minutes.

由于可能丢失"不会随着时间的推移而增加,因此可以安全地假设我没有内存泄漏吗?

Since 'possibly lost' doesn't increase over time, is it safe to assume that I do not have a memory leak?

所有错误似乎都来自libglib,并且围绕着g_malloc0和g_realloc.

The errors all seem to come from libglib and revolve around g_malloc0 and g_realloc.

推荐答案

Possibly lost错误涵盖了涉及指针链的部分场景.我肯定会追究造成这种情况的原因,直到您可以确认这不是问题为止(至少,您的内存占用不会增长),因为它可以指示代码中的其他逻辑问题.

Possibly lost errors in valgrind cover a subset of scenarios involving pointer chains. 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.

有关更多信息,您还可以查看相关部分在valgrind手册中.

For more information, you can also have a look at the relevant section in the valgrind manual.

这篇关于Valgrind:内存泄漏还是没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆