首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

STL set 器皿内存泄漏(WTL)

2013-09-05 
STL set 容器内存泄漏(WTL)为什么下面定义的那个m_aWindows会造成内存泄漏,不明白啊,有哪位大神知道的吗?

STL set 容器内存泄漏(WTL)
为什么下面定义的那个m_aWindows会造成内存泄漏,不明白啊,有哪位大神知道的吗?我试过了,用vector不会提示泄漏,但是用set就会,好像map也会, 这该怎么办啊,是误报还是什么的,求大神路过啊,这真的需要大神来解答呀,我问了好多人,包括工作好几年的他们都不知道呀,我们搞WTL的,对STL知道的少之又少啊

int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
HRESULT hRes = ::CoInitialize(NULL);
// If you are running on NT 4.0 or higher you can use the following call instead to 
// make the EXE free threaded. This means that calls come in on a random RPC thread.
//HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
ATLASSERT(SUCCEEDED(hRes));

// this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
::DefWindowProc(NULL, 0, 0, 0L);

AtlInitCommonControls(ICC_BAR_CLASSES);// add flags to support other controls

hRes = _Module.Init(NULL, hInstance);
ATLASSERT(SUCCEEDED(hRes));

int nRet = Run(lpstrCmdLine, nCmdShow);

_Module.Term();
::CoUninitialize();

std::set<HWND> m_aWindows;
for (std::set<HWND>::iterator it = m_aWindows.begin(); it != m_aWindows.end(); it++)
{
delete *it;
}
m_aWindows.clear();

#if _DEBUG
_CrtDumpMemoryLeaks();
#endif

return nRet;
} 内存泄漏 STL WTL set CRT
[解决办法]
_CrtDumpMemoryLeaks();调用时间不对,set还没出作用范围内,还能够正常使用,至少应该等set析构之后再调用_CrtDumpMemoryLeaks();

热点排行