valgrind比释放更多的分配但没有泄漏

时间:2013-09-19 15:32:42

标签: valgrind

我遇到了问题.. 当我用我的程序运行valgrind时,我得到了以下输出,这让我很困惑:

==12919== HEAP SUMMARY:
==12919==     in use at exit: 97,820 bytes in 1 blocks
==12919==   total heap usage: 17 allocs, 16 frees, 99,388 bytes allocated
==12919==
==12919== LEAK SUMMARY:
==12919==    definitely lost: 0 bytes in 0 blocks
==12919==    indirectly lost: 0 bytes in 0 blocks
==12919==      possibly lost: 0 bytes in 0 blocks
==12919==    still reachable: 97,820 bytes in 1 blocks
==12919==         suppressed: 0 bytes in 0 blocks
==12919== Reachable blocks (those to which a pointer was found) are not shown.
==12919== To see them, rerun with: --leak-check=full --show-reachable=yes
==12919==
==12919== For counts of detected and suppressed errors, rerun with: -v
==12919== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 6 from 6)

2 个答案:

答案 0 :(得分:2)

我发现它是由编译“-pg”标志引起的。没有它一切都好!

答案 1 :(得分:0)

来自valgrind faq

  

5.2。使用Memcheck的内存泄漏检测器,“绝对丢失”,“间接丢失”,“可能丢失”,“仍然可以访问”和“抑制”之间的区别是什么?

详情请参阅用户手册的Memcheck部分。

简而言之:

"definitely lost" means your program is leaking memory -- fix those leaks!

"indirectly lost" means your program is leaking memory in a pointer-based structure. (E.g. if the root node of a binary tree is "definitely lost", all the children will be "indirectly lost".) If you fix the "definitely lost" leaks, the "indirectly lost" leaks should go away.

"possibly lost" means your program is leaking memory, unless you're doing unusual things with pointers that could cause them to point into the middle of an allocated block; see the user manual for some possible causes. Use --show-possibly-lost=no if you don't want to see these reports.

"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.

"suppressed" means that a leak error has been suppressed. There are some suppressions in the default suppression files. You can ignore suppressed errors.