Steven smethurst Steven smethurst - 1 year ago 178
C++ Question

memory leak unit test c++

I have just resolved a memory leak in my application and now I want to write a unit test to ensure that this does not happen again.

I'm look for a way to detect the memory usage of the current application (working set), before and after some functions.

For example:

long mem_used= GetMemUsed();
/* Do some work */
/* clean up */

if( mem_used != GetMemUsed() ) {
Error( "Memory leek" );

I have found plenty of ways to detect the memory usage across the entire system but none for just the current application.

Suggestions, links, code snippets?

Answer Source

Boost.Test will automatically tell you at the end of a test run if any of your unit tests leaked memory.

I don't know if any of the other C++ unit testing frameworks provide this kind of functionality.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download