我有一个 C++ windows 应用程序,它有一些内存泄漏问题。是否可以使用 NTSD 分析转储中的内存泄漏?如果是这样,请指导我如何做到这一点?
我还听说我们可以使用用户模式转储来做到这一点。我对在 Windows 中发现泄漏不是很熟悉。在 Linux 中使用 Valgrind 非常容易。
有没有其他更好的选择来检查这个?
有关 Visual Leak Detector 的详细信息,请参见此处。我在 Windows 上使用过它。你在申请中所做的就是
#include <vld.h>
调试程序时,您将在终端中看到有关检测到泄漏的报告,如下所示:
---------- Block 1199 at 0x04BE1058: 136 bytes ----------
Call Stack:
d:\Foobar\FooLog.cpp (26): FooLog::getInstance
d:\Foobar\FooMain.cpp (75): FooMain::init
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (578): __tmainCRTStartup
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (403): WinMainCRTStartup
0x759A3677 (File and line number not available): BaseThreadInitThunk
0x770C9D42 (File and line number not available): RtlInitializeExceptionChain
0x770C9D15 (File and line number not available): RtlInitializeExceptionChain
Data:
9C 33 2D 6B 74 2A 2D 6B C8 11 BE 04 00 00 00 00 .3-kt*-k ........
00 00 00 00 70 14 BB 6C 70 14 BB 6C 00 00 00 00 ....p..l p..l....
00 00 00 00 68 14 BB 6C 68 14 BB 6C 00 00 00 00 ....h..l h..l....
00 00 00 00 6C 14 BB 6C 6C 14 BB 6C 20 12 BE 04 ....l..l l..l....
00 00 00 00 CD 00 CD CD 00 00 00 00 01 CD CD CD ........ ........
68 14 BB 6C 78 33 2D 6B 00 00 00 00 00 00 00 00 h..lx3-k ........
我使用DrMemory追踪内存和资源泄漏取得了巨大成功。它适用于 GCC 和 MSVC,使用起来非常简单。