简体   繁体   English

_CrtMem *和调试堆

[英]_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?

I cut and pasted your code and tested it on my machine under VS2008 and _CrtMemDifference returns 0 ... 我剪切并粘贴了您的代码,并在VS2008下在我的计算机上对其进行了测试,并且_CrtMemDifference返回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? 是否有可能另一个线程在2个_CrtMemCheckpoint调用之间分配了东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM