Microsoft KB Archive/309121

= BUG: Nested Dialog Boxes Leak Memory =

Article ID: 309121

Article Last Modified on 8/18/2005

-

APPLIES TO


 * Microsoft Office Keyboard

-



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 &quot;CParentDlg&quot; with one button called &quot;Button1&quot; 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); }

Keywords: kbbug kbpending KB309121

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.