The code is pretty simple:
#include <vector>
int main() {
std::vector<int> v;
}
Then I create and run it using Valgrind:
g++ test.cc && valgrind ./a.out
==8511== Memcheck, a memory error detector
==8511== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==8511== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==8511== Command: ./a.out
==8511==
==8511==
==8511== HEAP SUMMARY:
==8511== in use at exit: 72,704 bytes in 1 blocks
==8511== total heap usage: 1 allocs, 0 frees, 72,704 bytes allocated
==8511==
==8511== LEAK SUMMARY:
==8511== definitely lost: 0 bytes in 0 blocks
==8511== indirectly lost: 0 bytes in 0 blocks
==8511== possibly lost: 0 bytes in 0 blocks
==8511== still reachable: 72,704 bytes in 1 blocks
==8511== suppressed: 0 bytes in 0 blocks
==8511== Rerun with --leak-check=full to see details of leaked memory
==8511==
==8511== For counts of detected and suppressed errors, rerun with: -v
==8511== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
The question is twofold:
(1) “General use of the heap” means that there is 1 allocation and 0 for free. I assume 1 alloc is that the std :: vector instance needs a piece of memory on the heap. It's great; but why does he not free his memory during destruction?
(2) And if he does not release it, why is there no memory leak in LEAK SUMMARY?
(3) By the way, what does it mean ==8511==in front of each line? (I could find this in the manual, however, you do not need to answer this question)
Thank!