Clark Gaebel
Clark Gaebel

Reputation: 17948

_CrtMem* and the debug heap

When I use the following code, it detects a memory leak. How can I make it not?

_CrtMemState startState;
_CrtMemState endState;
_CrtMemState temp;

_CrtMemCheckpoint(&startState);
const char* foo = "I'm not leaking memory! Stop saying I am!";
_CrtMemCheckpoint(&endState);

_CrtMemDifference(&temp, &startState, &endState);    // Returns true. Wtf?

Upvotes: 1

Views: 696

Answers (1)

Goz
Goz

Reputation: 62323

I cut and pasted your code and tested it on my machine under VS2008 and _CrtMemDifference returns 0 ...

As the oft heard adage goes: "Works on my machine" ;)

Edit: Have you got multiple threads running? Is it possible another thread has allocated something between the 2 _CrtMemCheckpoint calls?

Upvotes: 1

Related Questions