C ++ unit test memory leak

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

I am looking for a way to determine the memory usage of the current application (working set) before and after some functions.

For instance:

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

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

I found many ways to detect memory usage throughout the system, but none of them are used only for the current application.

Suggestions, links, code snippets?

+5
source share
6 answers

Boost.Test will automatically inform you at the end of the test run if any of your modules checks for a memory leak.

, - ++ ​​.

+6

ValGrind . ; .

+6

unit test. , - , , , , , , . , delete... , .

, , - unit test. .

+3

Linux , GLibC, , . , ​​ , malloc, .

+3

Google Analytics (gtest), google (gperf), . GPerf , , pprof - , , .. , .

Valgrind, , , gperf. , gperf Valgrind, , , .

0

All Articles