c++ - 奇怪的 "Memory Leak Detection"错误 C++

标签 c++ visual-c++ memory memory-leaks

我有一个非常奇怪的内存泄漏问题。我使用 _CrtDumpMemoryLeaks 来检查泄漏。这是我的 WinMain 函数:

int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
                     _In_opt_ HINSTANCE hPrevInstance,
                     _In_ LPTSTR    lpCmdLine,
                     _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

    ////////////////// SET UP CHECKS FOR MEMORY LEAKS ////////////////////
    _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    //////////////////////////////////////////////////////////////////////


    _CrtDumpMemoryLeaks(); // Reports leaks to stderr

    return 0;
}

如您所见,我已经完全删除了其中的所有内容,只是为了检查我是否收到了某种误报。

在我关闭一个应用程序后,我在输出中得到了这堆内存泄漏:

Detected memory leaks!
Dumping objects ->
{1343} normal block at 0x06076780, 8 bytes long.
 Data: < g      > 20 67 07 06 00 00 00 00 
{1342} normal block at 0x06076710, 52 bytes long.
 Data: <@   @   @       > 40 16 07 06 40 16 07 06 40 16 07 06 01 00 CD CD 
{1341} normal block at 0x060766B0, 32 bytes long.
 Data: <C:/Windows/Fonts> 43 3A 2F 57 69 6E 64 6F 77 73 2F 46 6F 6E 74 73 
{1339} normal block at 0x0607F438, 16 bytes long.
 Data: <              P > C0 17 0B 01 01 00 00 00 01 00 00 00 80 13 50 04 
{1338} normal block at 0x04501380, 8 bytes long.
 Data: <    H   > BC 0D 0B 01 48 18 07 06 
{1295} normal block at 0x060716B0, 8 bytes long.
 Data: <        > B4 B3 0B 01 00 00 00 00 
{1294} normal block at 0x06071640, 52 bytes long.
 Data: < g   g   g      > 10 67 07 06 10 67 07 06 10 67 07 06 01 01 CD CD 
{1293} normal block at 0x0450DFB8, 8 bytes long.
 Data: < !    P > E0 21 0B 01 98 05 50 04 
{1292} normal block at 0x0450E110, 8 bytes long.
 Data: <  P     > E8 05 50 04 00 00 00 00 
// (There's like thousand more of those...)
Object dump complete.

我完全不知道它们是从哪里来的。

提前感谢您的回答。

最佳答案

检查输出窗口。您是否看到正在加载一堆 DLL?在您调用泄漏输出之前,它们中的任何一个都可能正在静态初始化未释放的数据结构。试试小费here通过将泄漏检查包含在特定的执行时间范围内来排除一些噪音。

Since the statically initialized Google Test singleton requires allocations on the heap, the Visual C++ memory leak detector will report memory leaks at the end of the program run. The easiest way to avoid this is to use the _CrtMemCheckpoint and _CrtMemDumpAllObjectsSince calls to not report any statically initialized heap objects. See MSDN for more details and additional heap check/debug routines.

关于c++ - 奇怪的 "Memory Leak Detection"错误 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13382201/

相关文章:

c++ - 复制 float 的字节模式不起作用

r - 如何在不耗尽内存的情况下将非常大的 OpenStreetMap 文件划分为 R 中的较小文件?

python - 如何使用 boost.python 跨模块使用类?

c++ - 如何在不完全 boost 的情况下使用 boost.xpressive ?

c++ - 定义内核大小(C++ OpenCV)

c++ - 为什么无法访问使用 using 声明引入的私有(private)基类的成员模板?

c# - 在托管 C# 中释放非托管 c 代码内存

c++ - 如何编写一个简单的调试器?

C++ vector : unused capacity

c++ - 错误 LNK2001 : unresolved external symbol "private: static class