+ 3

Can we verify deallocation of heap memory for array?

Hello We know that delete and delete[] are used for memory release. Doing just delete on array result into memory leak like p1 in attached code. Can we observe by any means that p1 is only releasing 4 and 4 are missing ? https://code.sololearn.com/cG4s1Nv6COZ8/?ref=app

30th Sep 2021, 10:24 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
1 Odpowiedź
+ 3
Unfortunately there is no standard way to find out the size of memory a pointer is pointing to ( sizeof (ptr) will always return size of pointer type itself ) Although you can make use of tools like static analyzers and valgrind to find potential leaks in your program.
1st Oct 2021, 12:54 AM
Arsenic
Arsenic - avatar