I\'m trying to implement unit testing for my code and I\'m having a hard time doing it.
Ideally I would like to test some classes not only for good functionality but
You can use Google's tcmalloc allocation library, which provides a heapchecker.
(Note that heapchecking may add noticeable overhead to your program's performance, so you probably only want to enable it on debug builds or unit tests.)
And you asked for example code, so here it is.