Vjeetje
Vjeetje

Reputation: 5404

detect memory leak in visual studio c++ between two lines

I would like to detect memory leaks in visual studio c++. But instead of checking the whole solution, I would like to check for memory leaks between two code lines or a function. I don't want to check for memory leaks in the whole solution. For example:

// some code
startMemoryLeakDetection()
// other code
stopAndReportMemoryLeakDetection()
// some other code

Can anyone guide me to the necessary tools / programs?

Upvotes: 1

Views: 503

Answers (1)

shivakumar
shivakumar

Reputation: 3407

You can identify memory leak by using CRT dump and also using memory state comparison to get the statistics. Please refer steps given in MSDN for more details

_CrtMemCheckpoint( &s1 );
// memory allocations take place here
_CrtMemCheckpoint( &s2 );

if ( _CrtMemDifference( &s3, &s1, &s2) )
   _CrtMemDumpStatistics( &s3 );

http://msdn.microsoft.com/en-us/library/x98tx3cf.aspx

Upvotes: 3

Related Questions