This is platform dependent question for Linux. And if it matters, I'm asking specifically about pre-C++11.
I want to indirectly test a class's destructor by new
and delete
to see if all of the memory on the program's heap is deallocated, which could check for memory leaks.
object* x; //pointer allocated on the stack
... //measure available heap space
x = new object(); //allocated on the heap
delete x; //deallocate that heap space
... //measure again, see if it's the same
I understand that Valgrind has Massif (...is there a C++ library for Massif..?), and that I can even run a memory leak check on my entire program, but code changes. Unit tests are important, and it bugs me to death that I can't fully unit test all of my code.
What code can I write that would measure available heap space?