Memory Leak!
-
hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this:
virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } }
} I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilche -
hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this:
virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } }
} I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilcheThe right way to do this is to
delete
it in thePostNcDestroy
void CYourDlg::PostNcDestroy()
{
CDialog::PostNcDestroy();
delete this;
}Regards, Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this:
virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } }
} I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilcheYou're destroying the dialog C++ object before the dialog window has been destroyed. Call
m_pDlg->DestroyWindow()
(assuming these are modeless) and calldelete this;
in each dialog'sPostNCDestroy()
. --Mike-- Just released - RightClick-Encrypt v1.3 - Adds fast & easy file encryption to Explorer My really out-of-date homepage Sonork-100.19012 Acid_Helm -
hello everybody! I have some trouble in freeing up the memory allocated for dialog items. I have created the Gui screens using new and I use DestroyScreen to free my memory like this:
virtual void DestroyScreen(void) { if (m_pDlg->GetSafeHwnd()) { delete m_pDlg; m_pDlg = NULL; } }
} I go through each dlg using this DestroyScreen function. The returned warning is: Warning: calling DestroyWindow in CDialog::~CDialog -- OnDestroy or PostNcDestroy in derived class will not be called. Detected memory leaks! Dumping objects -> {3539} client block at 0x0081A330, subtype 0, 332 bytes long. a CDialog object at $0081A330, 332 bytes long Could anyone please help me with this one? Thanks everyone! Cheers, wilchelet me guess ur problem: m_pDlg is a pointer to CDialog or its sub-class, say XDialog. instances are not from XDialog, but its sub-class. if my guess is correct, simply change distructor to 'virtual' one. that is all. for MFC class, it is not necessary to call Destroy, MFC can do it itself. includeh10