我最近安装了VLD以尝试在Visual Studio 2008中调试C ++ MDI MFC应用程序.VLD报告了内存泄漏,无论我做了什么都无法解决问题,因此我创建了一个全新的空白项目(MDi MFC) )并且内存泄漏仍然出现。我做的唯一修改是在主#include <vld.h>
文件中编写Project.h
。文档说它与哪个文件无关,所以这里是执行后的输出(只需选择文件/退出而不执行任何其他操作)。
'Project.exe': Loaded 'C:\Users\MasterHD\Documents\Visual Studio 2008\Projects\Project\Debug\Project.exe', Symbols loaded.
'Project.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'Project.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugmfc_1fc8b3b9a1e18e3b_9.0.21022.8_none_9b54853441e399d5\mfc90ud.dll', Symbols loaded.
'Project.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll', Symbols loaded.
'Project.exe': Loaded 'C:\Windows\SysWOW64\user32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\lpk.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\usp10.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\shlwapi.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\msimg32.dll'
'Project.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_41e6975e2bd6f2b2\comctl32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll'
'Project.exe': Loaded 'D:\Program Files (x86)\Visual Leak Detector\bin\Win32\vld_x86.dll'
'Project.exe': Loaded 'D:\Program Files (x86)\Visual Leak Detector\bin\Win32\dbghelp.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll'
'Project.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc90.mfcloc_1fc8b3b9a1e18e3b_9.0.30729.6161_none_49768ef57548175e\MFC90ENU.DLL', Binary was not built with debug information.
Visual Leak Detector Version 2.4RC2 installed.
'Project.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll'
'Project.exe': Loaded 'C:\Windows\SysWOW64\clbcatq.dll'
WARNING: Visual Leak Detector detected memory leaks!
---------- Block 981 at 0x005BF560: 48 bytes ----------
Leak Hash: 0x32D8578B, Count: 1, Total 48 bytes
Call Stack (TID 9552):
f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c (159): MSVCR90D.dll!_malloc_dbg
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxmem.cpp (407): mfc90ud.dll!operator new + 0x16 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\afxmem.cpp (61): mfc90ud.dll!operator new + 0x13 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp (479): mfc90ud.dll!CWnd::FilterToolTipMessage + 0x11 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\tooltip.cpp (374): mfc90ud.dll!CWnd::_FilterToolTipMessage
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp (1070): mfc90ud.dll!CWnd::PreTranslateMessage
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\barcore.cpp (372): mfc90ud.dll!CControlBar::PreTranslateMessage + 0xC bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\wincore.cpp (2946): mfc90ud.dll!CWnd::WalkPreTranslateTree + 0x14 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (233): mfc90ud.dll!AfxInternalPreTranslateMessage + 0x12 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (777): mfc90ud.dll!CWinThread::PreTranslateMessage + 0x9 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (252): mfc90ud.dll!AfxPreTranslateMessage + 0x11 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (178): mfc90ud.dll!AfxInternalPumpMessage + 0x18 bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (900): mfc90ud.dll!CWinThread::PumpMessage
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\thrdcore.cpp (629): mfc90ud.dll!CWinThread::Run + 0xD bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appcore.cpp (865): mfc90ud.dll!CWinApp::Run
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\winmain.cpp (47): mfc90ud.dll!AfxWinMain + 0xD bytes
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\appmodul.cpp (30): Project.exe!wWinMain
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (574): Project.exe!__tmainCRTStartup + 0x35 bytes
f:\dd\vctools\crt_bld\self_x86\crt\src\crtexe.c (399): Project.exe!wWinMainCRTStartup
0x76D8338A (File and line number not available): kernel32.dll!BaseThreadInitThunk + 0x12 bytes
0x77719F72 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x63 bytes
0x77719F45 (File and line number not available): ntdll.dll!RtlInitializeExceptionChain + 0x36 bytes
Data:
2C 00 00 00 00 00 00 00 F2 19 BA 00 00 E1 00 00 ,....... ........
00 00 00 00 00 00 00 00 18 00 00 00 17 00 00 00 ........ ........
00 00 00 00 FF FF FF FF 00 00 00 00 00 00 00 00 ........ ........
Visual Leak Detector detected 1 memory leak (1016 bytes).
Largest number used: 14482 bytes.
Total allocations: 1681878 bytes.
Visual Leak Detector is now exiting.
The program '[14684] Project.exe: Native' has exited with code 0 (0x0).
任何人都有任何见解或建议?我甚至无法确定导致内存泄漏的原因,更不用说在我的实际项目中了。
编辑:如果我使用&#34; X&#34;关闭应用程序在右上角,然后发生 NO 内存泄漏,但是当我使用文件/退出下拉菜单时,它总是显示1016字节泄漏。
答案 0 :(得分:1)
我已经很晚了但是我刚刚使用visual studio 2013和使用crtdbg泄漏检测遇到了同样的泄漏。在主窗口消息处理循环期间,PreTranslateMessage似乎调用FilterToolTipMessage。然后在下一个地方发生泄漏
if (pToolTip == NULL)
{
pToolTip = new CToolTipCtrl;
if (!pToolTip->Create(pOwner, TTS_ALWAYSTIP))
...
}
我看到清理它的唯一地方是以下创建调用是否失败。如果它没有失败,那么我没有看到该对象的任何其他清理。
代码位于“Microsoft Visual Studio 12.0 \ VC \ atlmfc \ src \ mfc \ tooltip.cpp”中。在版本中我有它的第416行