解码 valgrind 的输出 [英] Decoding output from valgrind

查看:23
本文介绍了解码 valgrind 的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解 valgrind 的输出,如下所示:valgrind --leak-check=yes 某个程序"

I'm trying to understand the output from valgrind having executed it as follows: valgrind --leak-check=yes "someprogram"

输出在这里:

==30347== 
==30347== HEAP SUMMARY:
==30347==     in use at exit: 126,188 bytes in 2,777 blocks
==30347==   total heap usage: 4,562 allocs, 1,785 frees, 974,922 bytes       
        allocated
==30347== 
==30347== LEAK SUMMARY:
==30347==    definitely lost: 0 bytes in 0 blocks
==30347==    indirectly lost: 0 bytes in 0 blocks
==30347==      possibly lost: 0 bytes in 0 blocks
==30347==    still reachable: 126,188 bytes in 2,777 blocks
==30347==         suppressed: 0 bytes in 0 blocks
==30347== Reachable blocks (those to which a pointer was found) are   
          not shown.
==30347== To see them, rerun with: --leak-check=full --show-reachable=yes
==30347== 
==30347== For counts of detected and suppressed errors, rerun with: -v
==30347== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)

根据输出,没有丢失字节,但似乎仍然存在可访问块.那么我有内存泄漏吗?

According to the output there are no lost bytes but there seems to be Still Reachable blocks. So do I have a memory leak?

在此先感谢您的帮助.

推荐答案

没有

您最关心的是无法访问的块.您在这里看到的是,仍有活动变量指向"可访问的内存块.它们仍在范围内.

You are most concerned with unreachable blocks. What you are seeing here is that there are active variables that are still "pointing" at reachable blocks of memory. They are still in scope.

一个无法访问的块是,例如,你动态分配的内存,使用了一段时间,然后所有对它的引用都超出了范围,即使程序仍在执行.由于您不再有任何指向它们的句柄,它们现在不可恢复,从而造成内存泄漏.

An unreachable block would be, for instance, memory that you have allocated dynamically, used for a period of time and then all of the references to it have gone out of scope even though the program is still executing. Since you no longer have any handles pointing to them they are now unrecoverable, creating a memory leak.

以下引用自 Valgrind 文档:

仍然可以访问"意味着您的程序可能没问题——它没有释放它可以拥有的一些内存.这是很常见的,而且通常是合理的.如果您不想看到这些报告,请不要使用 --show-reachable=yes.

"still reachable" means your program is probably ok -- it didn't free some memory it could have. This is quite common and often reasonable. Don't use --show-reachable=yes if you don't want to see these reports.

这篇关于解码 valgrind 的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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