ArticleS. JamesGrenning.
TddAndMemoryLeaks [add child]

TDD and Memory Leaks

I made the C++ unit test harness I use check for memory leaks on a test by test basis. I was amazed at how easily a leak can sneak into a C++ program. I think TDD is a great way to stamp out leaks in C++ programs.

Now that I have my leak detector running I see that there are standard library routines (string, stringstream for example) that are not so diligent. It seems that in some implementations of the standard library allocate things then do not release them until the program terminates (or maybe never). I added a control to the unit tests so that they can be optionally run twice. This provides some evidence that the library routines don’t habitually leak.


 Sun, 3 Apr 2005 03:09:44, Kelley Harris, Great idea. Details and code welcome.
Great idea James. I'd love to hear more details. Ideally I'd like to see the memory checks in the next release of the tool you use. (CppUnitLite[?]?) Any chance?
 Wed, 27 Apr 2005 18:52:17, James Grening, Simple memory leak checker
Hi Kelley

The leak detection is already part of CppTestTools[?], which contains an evolved version of CppUnitLite[?]. See's CppFit[?] page.

 Mon, 3 Oct 2005 18:45:22, Sheetal ,
 Mon, 3 Oct 2005 18:45:40, Hello , Hi

 Thu, 29 Jun 2006 06:31:22, asa, aaaa