C++ _CrtMem*和调试堆
当我使用以下代码时,它会检测到内存泄漏。我怎么能做到不呢C++ _CrtMem*和调试堆,c++,debugging,memory-leaks,C++,Debugging,Memory Leaks,当我使用以下代码时,它会检测到内存泄漏。我怎么能做到不呢 _CrtMemState startState; _CrtMemState endState; _CrtMemState temp; _CrtMemCheckpoint(&startState); const char* foo = "I'm not leaking memory! Stop saying I am!"; _CrtMemCheckpoint(&endState); _CrtMemDifference(&
_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?
我剪切并粘贴了您的代码,并在VS2008下的我的机器上进行了测试,_CrtMemDifference返回0 常言道:“在我的机器上工作”;)
编辑:你有多个线程在运行吗?是否有可能另一个线程在2个CrtMemCheckpoint调用之间分配了一些内容 我剪切并粘贴了您的代码,并在VS2008下的我的机器上进行了测试,_CrtMemDifference返回0 常言道:“在我的机器上工作”;)
编辑:你有多个线程在运行吗?是否有可能另一个线程在2个CrtMemCheckpoint调用之间分配了一些内容 如果代码更改为const char[]No repro,即使调用了_crtsetdbgfagflag(),它是否检测到泄漏。我没想到会有。如果代码更改为const char[]No repro,即使调用了_crtsetdbgfagflag(),它是否检测到泄漏。我没想到会这样。没关系,是我的错。无关代码。谢谢你的快速回复。没关系,是我的错。无关代码。谢谢你的快速回复。