BUG: Nested Dialog Boxes Leak Memory (309121)



The information in this article applies to:

  • Microsoft eMbedded Visual C++, Version:4.0

This article was previously published under Q309121

SYMPTOMS

When you dismiss a dialog box that was created as a child of another dialog box, some memory from the child dialog box will not be freed until the parent dialog box is dismissed.

CAUSE

Microsoft Foundation Classes (MFC) is not getting an opportunity to clean up any temporary objects that were created to support the child dialog box.

RESOLUTION

You can explicitly call CWinApp::OnIdle(), which will allow MFC to clean up its temporary objects.

STATUS

Microsoft has confirmed this to be a bug in MFC for Pocket PC.

MORE INFORMATION

To reproduce the problem scenario, assume that you have a dialog box implemented in a class called "CParentDlg" with one button called "Button1" on it. Clicking that button will bring up a second dialog box (represented by the dialog template IDD_CHILD). The following code illustrates this example:
void CParentDlg::OnButton1() 
{
	CDialog dlg( IDD_CHILD, this);
	dlg.DoModal();
}
				

If you use Remote Heap Walker to check the amount of free memory before and after this method is called, you will see that there is less free memory after the call, which indicates a memory leak.

It is necessary to call CWinApp::OnIdle() explicitly to give MFC a chance to clean up any temporary objects. Modifying the above code as follows will fix this problem:
void CParentDlg::OnButton1() 
{
	{
		CDialog dlg( IDD_CHILD, this);
		dlg.DoModal();
	}
	AfxGetApp()->OnIdle(1);
}
				

Modification Type:MinorLast Reviewed:8/18/2005
Keywords:kbbug kbpending KB309121