[問題] MFC SDI dll記憶體洩漏Memory Leak

看板C_and_CPP (C/C++)作者 (超越自己)時間10年前 (2016/01/19 11:05), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
開發平台(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
pDocument用完後有清成NULL之類的嗎
01/24 10:27, 1F

01/26 15:31, , 2F
回c大的話,有喔...習慣指標用完清除前,一定會指NULL
01/26 15:31, 2F
文章代碼(AID): #1MdQWJsh (C_and_CPP)
文章代碼(AID): #1MdQWJsh (C_and_CPP)