【问题标题】:Detecting Memory Leaks in C++ Windows application检测 C++ Windows 应用程序中的内存泄漏
【发布时间】:2013-04-16 22:11:33
【问题描述】:

我有一个存在一些内存泄漏问题的 C++ Windows 应用程序。是否可以使用 NTSD 分析转储中的内存泄漏?如果是这样,请指导我如何做到这一点?

我还听说我们可以使用用户模式转储来做到这一点。我对在 Windows 中发现泄漏不是很熟悉。在 Linux 中使用 Valgrind 非常容易。

还有其他更好的选择吗?

【问题讨论】:

标签: c++ windows


【解决方案1】:

see here 了解有关 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 ........

【讨论】:

  • 我将通过这个 VLD。我希望这对多线程应用程序也有用。
  • 以前从未听说过 VLD。 4 分钟后,我知道我没有内存泄漏,甜!我推荐它!
【解决方案2】:

我在使用DrMemory 追踪内存和资源泄漏方面取得了巨大成功。它适用于 GCC 和 MSVC,而且使用起来非常简单。

【讨论】:

  • 感谢便携式解决方案。肯定会经历这个。
猜你喜欢
  • 2011-03-29
  • 2012-02-22
  • 2018-01-17
  • 2011-10-09
  • 1970-01-01
  • 2021-09-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-14
相关资源
最近更新 更多