views:

39

answers:

1

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?
+1  A: 

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?

Goz
Nope. Fully single-threaded.
Clark Gaebel
Never mind, it was my fault. Unrelated code. Thanks for your quick response.
Clark Gaebel