[問題] MFC SDI dll記憶體洩漏Memory Leak
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++
各位板友大家好,
目前製作一MFC SDI dll,透過MFC Dialog呼叫該dll並呈現,
關閉dll時發現會出現「存取不該存取的記憶體位置」產生錯誤(0x000005),
上網查詢及自己追蹤程式碼後發現CFrameWnd若是SDI為dll時,
會刪除兩次Document。
http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc.docview/2004-03/0174.html
於是我將繼承的MyMainFrm類別中的OnClose改寫,
刪除其進入CFrameWnd的OnClose的程式碼,
並將OnClose的程式碼中的下午段複製至MyMainFrm的OnClose內。
如下:
--
// shut down with OnCloseDocument instead.
if (pDocument != NULL && pDocument->m_bAutoDelete) // <---- if DLL-module
then pDocument->NULL,NULL, etc. (FAIL)
{
BOOL bOtherFrame = FALSE;
POSITION pos = pDocument->GetFirstViewPosition();
while (pos != NULL)
{
CView* pView = pDocument->GetNextView(pos);
ASSERT_VALID(pView);
if (pView->GetParentFrame() != this)
{
bOtherFrame = TRUE;
break;
}
}
if (!bOtherFrame)
{
pDocument->OnCloseDocument();
return;
}
// allow the document to cleanup before the window is destroyed
pDocument->PreCloseFrame(this);
}
// then destroy the window
DestroyWindow();
--
但在程式結束時依然發現有Memory Leak..
想請問板友CDocManager及CPtrList在SDI是哪個函式被載入,
又是在什麼時候該被正常刪除呢?
謝謝大家...
Dumping objects ->
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\plex.cpp(29) : {357} normal block
at 0x03647650, 124 bytes long.
Data: < (ud > 00 00 00 00 00 00 00 00 00 00 00 00 28 75 64 03
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\doctempl.cpp(62) : {356} client
block at 0x036475F0, subtype c0, 32 bytes long.
a CDocManager object at $036475F0, 32 bytes long
f:\dd\vctools\vc7libs\ship\atlmfc\src\mfc\doctempl.cpp(60) : {355} client
block at 0x03646848, subtype c0, 28 bytes long.
a CPtrList object at $03646848, 28 bytes long
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.183.149
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1453172755.A.DAB.html
推
01/24 10:27, , 1F
01/24 10:27, 1F
→
01/26 15:31, , 2F
01/26 15:31, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章