c++ - Valgrind : is there a memory leak in the output? 总结

标签 c++ memory-leaks valgrind

我的程序是用 C++ 编写的,我运行了 valgrind 来检查内存问题。但是,我不太确定,当分配的内存多于释放的内存时会发生什么,但摘要显示没有泄漏。 以下是以下命令的输出:

valgrind --leak-check=full  ./myprogram

输出(Centos 6):

==28196== 
==28196== HEAP SUMMARY:
==28196==     in use at exit: 66,748 bytes in 1 blocks
==28196==   total heap usage: 7 allocs, 6 frees, 67,964 bytes allocated
==28196== 
==28196== LEAK SUMMARY:
==28196==    definitely lost: 0 bytes in 0 blocks
==28196==    indirectly lost: 0 bytes in 0 blocks
==28196==      possibly lost: 0 bytes in 0 blocks
==28196==    still reachable: 66,748 bytes in 1 blocks
==28196==         suppressed: 0 bytes in 0 blocks
==28196== Reachable blocks (those to which a pointer was found) are not shown.
==28196== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==28196== 
==28196== For counts of detected and suppressed errors, rerun with: -v
==28196== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2)
Profiling timer expired

有人可以详细说明抑制问题吗?

谢谢

最佳答案

仍然可以访问意味着您有指向内存的指针,但您在关机前没有释放它。在大多数情况下,这意味着不存在有问题的内存泄漏,因为大多数时候这是您填充的数据结构,但在关闭之前没有释放。

这个问题 Still Reachable Leak detected by Valgrind顶部答案中有更多解释。

编辑: 详细说明抑制,valgrind 可以读取文件以抑制某些错误,并且这个被抑制 2 from 2 的注释意味着还发现了抑制错误列表中的 2 个错误。错误通常会被抑制,因为它们位于第三方库中或已知不会导致问题。有关抑制错误的更多信息,请查看 valgrind's explanation of error suppression .

关于c++ - Valgrind : is there a memory leak in the output? 总结,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31816208/

相关文章:

c++ - 在 Qt 控制台应用程序中读写 QProcess

c++ - 套接字:向多个客户端发送消息

c++ - TypeDef 作为可重写的类特性

iphone - 为什么这段代码会产生内存泄漏?

c++ - 在 massif 工具中跟踪子进程的命令

c - 二叉树插入,帮我看一下valgrinds的资料

c++ - 在 Visual C++ 中读取 unicode 文本文件

python-3.x - 在 Linux 上被错误杀死的任务可以被认为是内存泄漏吗?

c++ - 无效异常展开导致的崩溃?

java - Java中的内存管理,加载大文件,如何释放对象?