There is such a code
int main(){ int* p = new int[2]; delete p; return 0; } I decided to view it through valgrind. Actually the results are
==3147== HEAP SUMMARY: ==3147== in use at exit: 72,704 bytes in 1 blocks ==3147== total heap usage: 2 allocs, 1 frees, 72,712 bytes allocated ==3147== ==3147== LEAK SUMMARY: ==3147== definitely lost: 0 bytes in 0 blocks ==3147== indirectly lost: 0 bytes in 0 blocks ==3147== possibly lost: 0 bytes in 0 blocks ==3147== still reachable: 72,704 bytes in 1 blocks ==3147== suppressed: 0 bytes in 0 blocks There are a few questions
- Where did as many as 2! request in a bunch. How many have I read, one siscol for one new was discussed, and here two.
- Why such a memory size of 72 704 bytes? It turns out this amount of memory is frozen in the heap and I only freed up 74,712 - 72,704 = 8 bytes (I have 4 bytes int ... wherefrom 8 freed bytes, I cannot understand (this is the size of the pointer in my architecture))
ps the value of the "allocs" doesn't depend on parameter in []. I've changed it on 20 elements
--track-origins=yes, then valgrind will print the call stack when the allocation was made. These 72k were probably allocated somewhere in the initialization block. Accordingly, it is false positive. - VTTdelete[]to delete an array - Ariox