1
考慮下面的代碼C++空程序存儲器泄漏
int main(){
return 0;
}
我克編譯它++並通過輸出到Valgrind的。輸出如下。
==11752== HEAP SUMMARY:
==11752== in use at exit: 72,704 bytes in 1 blocks
==11752== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==11752==
==11965== LEAK SUMMARY:
==11965== definitely lost: 0 bytes in 0 blocks
==11965== indirectly lost: 0 bytes in 0 blocks
==11965== possibly lost: 0 bytes in 0 blocks
==11965== still reachable: 72,704 bytes in 1 blocks
==11965== suppressed: 0 bytes in 0 blocks
然而,在用gcc C編譯中相同的代碼產生此Valgrind的輸出:
==11771== HEAP SUMMARY:
==11771== in use at exit: 0 bytes in 0 blocks
==11771== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==11771==
==11771== All heap blocks were freed -- no leaks are possible
它看起來像編譯
它看起來像空C++程序實際上分配內存和不釋放它(這不是一場災難,因爲它是一個「仍然可以」泄漏),我不知道爲什麼會發生這種情況。
我用g ++ 6.3在linux(solus os)上做了這個測試。
有人可以解釋發生了什麼?
無法在gcc 4.7.1上重現。這可能是6.3版本中的一個錯誤,請考慮報告它。 – mcrlc
[Valgrind:內存仍然可以使用普通程序使用](http://stackoverflow.com/questions/30376601/valgrind-memory-still-reachable-with-trivial-program-using-iostream) –
cbuchart