Help please : "Detected memory leaks!"
-
hai ... a have some problems with memory when creating Tabbed Dialogs ... (when TCITEM.lParam = pointer to dialog ..) every things i do correct, but after closing program debugger sad: Detected memory leaks! Dumping objects -> E:\home\projects\kTalk\MainDlg.cpp(343) : {105} client block at 0x00345438, subtype 0, 160 bytes long. a CDialog object at $00345438, 160 bytes long ... and e.t.c ... ==================== ovverriding i also destroying them ... CWnd *pWnd = (LPARAM)tci.lParam; delete pWnd; =============== maybe i should destroy them in other way ?? thanks ---------------- muaaa .. (:
-
hai ... a have some problems with memory when creating Tabbed Dialogs ... (when TCITEM.lParam = pointer to dialog ..) every things i do correct, but after closing program debugger sad: Detected memory leaks! Dumping objects -> E:\home\projects\kTalk\MainDlg.cpp(343) : {105} client block at 0x00345438, subtype 0, 160 bytes long. a CDialog object at $00345438, 160 bytes long ... and e.t.c ... ==================== ovverriding i also destroying them ... CWnd *pWnd = (LPARAM)tci.lParam; delete pWnd; =============== maybe i should destroy them in other way ?? thanks ---------------- muaaa .. (:
I could be just guessing (as usual, but finding a bug is just a matter of a right guess anyway). I'm just gonna write some typical bugs (i've had these problems myself recently): 1. Before deleting a window (CWnd object) destroy a window with ->DestroyWindow() unless it isn't done earlier. 2. Before destroying a window make sure it doesn't own some objects like brushes, device contexts etc. - it could be it 3. before destroying any brush/context etc. make sure it's not selected by other objects - that's something I'm aware of very much 4. before creating any object destroy the previous one (example - I've been calling CBrush::CreateSolidBrush twice for the same CBrush object without calling CBrush::DeleteObject) 5. Maybe that tab control is the reason (it or it's elements are not deleted or destroyed - read carefully what they say about deleting it and it's structures) Remember - be patient :-D (yeah, right... :suss: ) Greetings to all assembler dudes and especially for C64 demoscene!
-
hai ... a have some problems with memory when creating Tabbed Dialogs ... (when TCITEM.lParam = pointer to dialog ..) every things i do correct, but after closing program debugger sad: Detected memory leaks! Dumping objects -> E:\home\projects\kTalk\MainDlg.cpp(343) : {105} client block at 0x00345438, subtype 0, 160 bytes long. a CDialog object at $00345438, 160 bytes long ... and e.t.c ... ==================== ovverriding i also destroying them ... CWnd *pWnd = (LPARAM)tci.lParam; delete pWnd; =============== maybe i should destroy them in other way ?? thanks ---------------- muaaa .. (:
I'm not sure whether this will work, but it's simple to try. Override
PostNcDestroy
for your tabbed dialogs and adddelete this
as the last line of the function. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
I'm not sure whether this will work, but it's simple to try. Override
PostNcDestroy
for your tabbed dialogs and adddelete this
as the last line of the function. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo...but keep in mind that "delete this" can be dangerous ;) Just kiddin'. Although delete operator removes the object, the code always remain in the memory (one for all objects of course). I've just never seen anybody using "delete this". Greetings to all assembler dudes and especially for C64 demoscene!
-
...but keep in mind that "delete this" can be dangerous ;) Just kiddin'. Although delete operator removes the object, the code always remain in the memory (one for all objects of course). I've just never seen anybody using "delete this". Greetings to all assembler dudes and especially for C64 demoscene!
I agree with you the procedure is a little weird, but this is the standard way to cleanup MFC modeless dialogs, for instance. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I could be just guessing (as usual, but finding a bug is just a matter of a right guess anyway). I'm just gonna write some typical bugs (i've had these problems myself recently): 1. Before deleting a window (CWnd object) destroy a window with ->DestroyWindow() unless it isn't done earlier. 2. Before destroying a window make sure it doesn't own some objects like brushes, device contexts etc. - it could be it 3. before destroying any brush/context etc. make sure it's not selected by other objects - that's something I'm aware of very much 4. before creating any object destroy the previous one (example - I've been calling CBrush::CreateSolidBrush twice for the same CBrush object without calling CBrush::DeleteObject) 5. Maybe that tab control is the reason (it or it's elements are not deleted or destroyed - read carefully what they say about deleting it and it's structures) Remember - be patient :-D (yeah, right... :suss: ) Greetings to all assembler dudes and especially for C64 demoscene!
But i have done it !!! (: there is my DEL proc : int CMainDlg::DelTab(int Index) { TC_ITEM tci; CChatDlg *pWnd; int iCount = m_tabs.GetItemCount(); int iCurrent = m_tabs.GetCurSel(); m_tabs.GetItem(Index,&tci); ASSERT(tci.lParam); pWnd = (CChatDlg *)tci.lParam; //CChatDlg is CDialog pWnd->DestroyWindow(); pWnd = NULL; delete pWnd; m_tabs.DeleteItem(Index); }; Sometimes its works... but i can't found a bug .. (: there it is .. !? ---------------- muaaa .. (:
-
I'm not sure whether this will work, but it's simple to try. Override
PostNcDestroy
for your tabbed dialogs and adddelete this
as the last line of the function. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo -
But i have done it !!! (: there is my DEL proc : int CMainDlg::DelTab(int Index) { TC_ITEM tci; CChatDlg *pWnd; int iCount = m_tabs.GetItemCount(); int iCurrent = m_tabs.GetCurSel(); m_tabs.GetItem(Index,&tci); ASSERT(tci.lParam); pWnd = (CChatDlg *)tci.lParam; //CChatDlg is CDialog pWnd->DestroyWindow(); pWnd = NULL; delete pWnd; m_tabs.DeleteItem(Index); }; Sometimes its works... but i can't found a bug .. (: there it is .. !? ---------------- muaaa .. (:
Mandalay wrote: _there is my DEL proc :
int CMainDlg::DelTab(int Index)
{
TC_ITEM tci;
CChatDlg *pWnd;
int iCount = m_tabs.GetItemCount();
int iCurrent = m_tabs.GetCurSel();
m_tabs.GetItem(Index,&tci);
ASSERT(tci.lParam);
pWnd = (CChatDlg *)tci.lParam; //CChatDlg is CDialog
pWnd->DestroyWindow();
pWnd = NULL; // why do you do this?
delete pWnd; // this is a null pointer, why delete it?
m_tabs.DeleteItem(Index);
};Sometimes its works... but i can't found a bug .. (: there it is .. !?_ Why do you set the pointer to NULL before deletion? Perhaps I missed something in another reply to this message... Later, Nathan --------------------------- Hmmm... what's a signature?
-
But i have done it !!! (: there is my DEL proc : int CMainDlg::DelTab(int Index) { TC_ITEM tci; CChatDlg *pWnd; int iCount = m_tabs.GetItemCount(); int iCurrent = m_tabs.GetCurSel(); m_tabs.GetItem(Index,&tci); ASSERT(tci.lParam); pWnd = (CChatDlg *)tci.lParam; //CChatDlg is CDialog pWnd->DestroyWindow(); pWnd = NULL; delete pWnd; m_tabs.DeleteItem(Index); }; Sometimes its works... but i can't found a bug .. (: there it is .. !? ---------------- muaaa .. (:
Deleting a NULL pointer will do nothing and the original memory never gets freed. Try:
delete pWnd;
pWnd = NULL;Best regards, Alexandru Savescu
-
Mandalay wrote: _there is my DEL proc :
int CMainDlg::DelTab(int Index)
{
TC_ITEM tci;
CChatDlg *pWnd;
int iCount = m_tabs.GetItemCount();
int iCurrent = m_tabs.GetCurSel();
m_tabs.GetItem(Index,&tci);
ASSERT(tci.lParam);
pWnd = (CChatDlg *)tci.lParam; //CChatDlg is CDialog
pWnd->DestroyWindow();
pWnd = NULL; // why do you do this?
delete pWnd; // this is a null pointer, why delete it?
m_tabs.DeleteItem(Index);
};Sometimes its works... but i can't found a bug .. (: there it is .. !?_ Why do you set the pointer to NULL before deletion? Perhaps I missed something in another reply to this message... Later, Nathan --------------------------- Hmmm... what's a signature?
As I said: be patient - inspecting the code I've noticed You reversed the order of two code lines. The proper order is: delete pWnd; pWnd = NULL; ...no comment... ;) PS: Although delete doesn't set the pointer to NULL it is not necessarry to do that unless it's the only information about existance of an object. Greetings to all assembler dudes and especially for C64 demoscene!