问题描述
似乎每当有静态对象时,_CrtDumpMemoryLeaks返回一个假阳性声称它是泄漏的内存。我知道这是因为他们不会被销毁,直到main()(或WinMain)函数。但是有什么办法避免这种情况吗?我使用VS2008。
It seems whenever there are static objects, _CrtDumpMemoryLeaks returns a false positive claiming it is leaking memory. I know this is because they do not get destroyed until after the main() (or WinMain) function. But is there any way of avoiding this? I use VS2008.
推荐答案
我发现如果你告诉它在程序终止后自动检查内存,对象被考虑。我使用log4cxx和boost在静态块中做了大量的分配,这固定了我的假阳性...
I found that if you tell it to check memory automatically after the program terminates, it allows all the static objects to be accounted for. I was using log4cxx and boost which do a lot of allocations in static blocks, this fixed my "false positives"...
添加以下行,而不是调用_CrtDumpMemoryLeaks ,在main()的开头部分:
Add the following line, instead of invoking _CrtDumpMemoryLeaks, somewhere in the beginning of main():
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
有关使用和宏的详细信息,请参阅MSDN文章:
For more details on usage and macros, refer to MSDN article:
这篇关于如何忽略来自_CrtDumpMemoryLeaks的假阳性内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!