Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, it is memory leak in your case but you can avoid memory leak in cases where modeless dialog allocated on the heap by making use of overriding <code>PostNcDestroy</code>.</p> <p>Dialogs are not designed for auto-cleanup ( where as Main frame windows, View windows are). In case you want to provide the auto-cleanup for dialogs then you must override the <code>PostNcDestroy</code> member function in your derived class. To add auto-cleanup to your class, call your base class and then do a <code>delete this</code>. To remove auto-cleanup from your class, call <code>CWnd::PostNcDestroy</code> directly instead of the <code>PostNcDestroy</code> member in your direct base class.</p> <pre><code>void MyDialog::PostNcDestroy() { CDialog::PostNcDestroy(); delete this; } </code></pre> <p>How this works (from MSDN):</p> <blockquote> <p>When destroying a Windows window, the last Windows message sent to the window is WM_NCDESTROY. The default CWnd handler for that message (CWnd::OnNcDestroy) will detach the HWND from the C++ object and call the virtual function PostNcDestroy. Some classes override this function to delete the C++ object.</p> <p>"delete this" will free any C++ memory associated with the C++ object. Even though the default CWnd destructor calls DestroyWindow if m_hWnd is non-NULL, this does not lead to infinite recursion since the handle will be detached and NULL during the cleanup phase.</p> </blockquote> <p>You can also refer MSDN (<a href="http://msdn.microsoft.com/en-us/library/5zba4hah(VS.80).aspx" rel="noreferrer">Destroying Window Objects</a> ) for further details.</p> <p><strong>Note:</strong></p> <p>This works for modeless dialog that can be allocated on the <strong>heap</strong>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload