C++ 在 Windows x64 中检查内存泄漏的免费应用程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14235858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Free Application to check Memory Leaks in Windows x64?
提问by Cool_Coder
I have been assigned to check memory leak for an API by my boss. The Application is created in C & C++. So there is a possibility that memory is allocated using malloc & new. I want to check the memory leak in Visual Studio 2010 in debugger mode in 64 bit Windows 7. The problem with task manager is that it is not showing stable readings (memory increasing & decreasing by small amounts). Also the difference is small before & after the API is run. So i cannot defitely say that x amount of memory is leaking per cycle.
我的老板指派我检查 API 的内存泄漏。应用程序是用 C 和 C++ 创建的。所以有可能使用 malloc & new 分配内存。我想在 64 位 Windows 7 的调试器模式下检查 Visual Studio 2010 中的内存泄漏。任务管理器的问题是它没有显示稳定的读数(内存少量增加和减少)。在 API 运行之前和之后差异也很小。所以我不能肯定地说每个周期有 x 内存泄漏。
I have searched on the internet & found that linux has a great tool for this. However I want a reliable tool for my requirements (Windows 7). I have come across these:
我在互联网上搜索并发现 linux 有一个很好的工具。但是我想要一个可靠的工具来满足我的要求(Windows 7)。我遇到过这些:
http://winleak.sourceforge.net/
http://winleak.sourceforge.net/
http://sourceforge.net/projects/duma/?source=recommended
http://sourceforge.net/projects/duma/?source=recommended
As mentioned over here:
正如这里提到的:
the tool
工具
http://technet.microsoft.com/en-us/library/bb457063.aspx
http://technet.microsoft.com/en-us/library/bb457063.aspx
is not useful for my requirements. It would be very helpful of you guys if you could please suggest a good tool, as the customer who is requesting this is very important for our company. Thank You!
对我的要求没有用。如果您能推荐一个好的工具,那将对你们非常有帮助,因为提出此要求的客户对我们公司非常重要。谢谢你!
采纳答案by Ivaylo Strandjev
I suggest using visual leak detectoras it have served me well several times. You may also try to use valgrind for windows (although I had little success on doing that).Dr. Memoryalso helped me a few times.
我建议使用视觉检漏仪,因为它已经多次为我服务。您也可以尝试在 Windows 上使用 valgrind(尽管我在这方面收效甚微)。记忆博士也帮了我几次。
EDIT: also have a look here.
编辑:也看看这里。
回答by Helge Klein
The CRT library has its own memory leak detection mechanism. The output is not as detailed as what Visual Leak Detector gives you, but it is a lot faster than VLD (which easily runs for dozens of minutes after the program exits).
CRT 库有自己的内存泄漏检测机制。输出没有 Visual Leak Detector 给你的那么详细,但它比 VLD 快很多(它很容易在程序退出后运行几十分钟)。
To enable CRT memory leak detection place the following at the beginning of stdafx.h
(or somewhere else suitable):
要启用 CRT 内存泄漏检测,请将以下内容放在开头stdafx.h
(或其他合适的地方):
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
Add the following right before the program's exit point(s):
在程序的退出点之前添加以下内容:
_CrtDumpMemoryLeaks();
When _CrtDumpMemoryLeaks()
is called it prints all leaked memory it can find to the output window.
当_CrtDumpMemoryLeaks()
被调用时,它会将它可以找到的所有泄漏内存打印到输出窗口。
More information on MSDN.
有关MSDN 的更多信息。
Note:When I used this I only got the less detailed output without line numbers although I had defined _CRTDBG_MAP_ALLOC
right at the beginning of stdafx.h
.
注意:当我使用它时,我只得到了没有行号的不太详细的输出,尽管我_CRTDBG_MAP_ALLOC
在stdafx.h
.