为什么任何可执行文件泄漏内存

时间:2015-09-22 10:16:59

标签: c++ memory-leaks valgrind

即使

int
main () {
  return 0;
}

泄漏记忆。实际上,运行valgrind [0]输出

==21013== HEAP SUMMARY:
==21013==     in use at exit: 72,704 bytes in 1 blocks
==21013==   total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==21013== 
==21013== LEAK SUMMARY:
==21013==    definitely lost: 0 bytes in 0 blocks
==21013==    indirectly lost: 0 bytes in 0 blocks
==21013==      possibly lost: 0 bytes in 0 blocks
==21013==    still reachable: 72,704 bytes in 1 blocks
==21013==         suppressed: 0 bytes in 0 blocks

为什么会这样?如果Valgrind应该使用c ++进行泄漏检查失败,我应该如何亲自检查内存泄漏?

[0],echo "int main() { return 0; }"|c++ -x c++ - -o Main && valgrind ./Main

1 个答案:

答案 0 :(得分:7)

Valgrind告诉你,一切都没事,什么都没有泄露:

definitely lost: 0 bytes
indirectly lost: 0 bytes
  possibly lost: 0 bytes