Is this a memory leak in MFC

后端 未结 3 830
太阳男子
太阳男子 2021-01-02 14:50
// CMyDialog inherits from CDialog 
void CMyFrame::OnBnClickedCreate()
{
    CMyDialog* dlg = new CMyDialog();
    dlg->Create( IDD_MYDIALOG, m_thisFrame );
    d         


        
3条回答
  •  滥情空心
    2021-01-02 15:19

    Yes, that's a leak. And yes, the window would be destroyed if the object was stack-allocated. Using dialogs as stack-allocated objects is typical for modal dialogs - you call a method for showing a dialog as a modal window and that method only returns when the dialog is closed and the object is destroyed after that.

提交回复
热议问题