如何忽略来自 _CrtDumpMemoryLeaks 的误报内存泄漏?

How to ignore false positive memory leaks from _CrtDumpMemoryLeaks?(如何忽略来自 _CrtDumpMemoryLeaks 的误报内存泄漏?)
本文介绍了如何忽略来自 _CrtDumpMemoryLeaks 的误报内存泄漏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

似乎只要有静态对象,_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"...

在 main() 开头的某处添加以下行,而不是调用 _CrtDumpMemoryLeaks:

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:

http://msdn.microsoft.com/en-us/library/5at7yxcs(v=vs.71).aspx

这篇关于如何忽略来自 _CrtDumpMemoryLeaks 的误报内存泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

OpenGL transforming objects with multiple rotations of Different axis(OpenGL 变换不同轴多次旋转的对象)
GLFW first responder error(GLFW 第一响应者错误)
SOIL not linking correctly(SOIL 连接不正确)
Core profile vs version string? Only getting GLSL 1.3/OGL 3.0 in mesa 10.0.1(核心配置文件与版本字符串?在 mesa 10.0.1 中只获得 GLSL 1.3/OGL 3.0)
What is the range of OpenGL texture ID?(OpenGL 纹理 ID 的范围是多少?)
How taxing are OpenGL glDrawElements() calls compared to basic logic code?(与基本逻辑代码相比,OpenGL glDrawElements() 调用的繁重程度如何?)