I've been out of programming for a few years, just recently loaded VS2005 onto a system and decided to try getting my feet wet. I've got an MFC app that I'm working on and I'm stuck with a memory leak that I can't seem to resolve.
In the app class I'm reading command line arguments to determine whether to display a dialog or window. My InitInstance function contains code something like this:
I'm certain that I've used similar code to this in the past and I never had a memory leak. I'm also fairly certain that it required a delete call in the event that I'm using dynamic memory allocation for CWnd derived class rather than the dialog. The problem I've run into is I can't figure out where to put the delete. I've tried a [tt][blue]delete this[/blue];[/tt] in the window's destructor and I've tried deleting m_pMainWnd in the app's ExitInstance but neither does anything (as a matter of fact, by the time the ExitInstance function is called m_pMainWnd is NULL).
I'm sure I'm missing something simple but I just can't see or remember what it is. Any suggestions?
In the app class I'm reading command line arguments to determine whether to display a dialog or window. My InitInstance function contains code something like this:
Code:
[green]//...[/green]
BOOL bRetVal = FALSE;
CMyWnd* pWnd = NULL;
CMyDlg dlg;
[blue]if[/blue](bDialog)
{
m_pMainWnd = &dlg;
dlg.DoModal();
}
[blue]else[/blue]
{
pWnd = [blue]new[/blue] CMyWnd;
m_pMainWnd = pWnd;
[green]//Overridden create function[/green]
pWnd->Create(NULL);
RetVal = TRUE;
}
[blue]return[/blue] RetVal;
I'm sure I'm missing something simple but I just can't see or remember what it is. Any suggestions?