程序如下:
CFindReplaceDialog *m_pFindDialog;
afx_msg void OnEditFind(WPARAM,LPARAM);
-------------------------------------
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
    ON_COMMAND(ID_EDIT_FIND,OnEditFind)
END_MESSAGE_MAP()void OnEditFind()
{
    m_pFindDialog = new CFindReplaceDialog;
    m_pFindDialog->Create(TRUE,NULL,NULL,FR_DOWN,this);
}不论在何处加上delete,都出访问冲突的错
是不是核心对象能够自释放?若是,它在何时释放?期待解答

解决方案 »

  1.   

    When you implement a modeless dialog box, always override the OnCancel member function and call DestroyWindow from within it. Don’t call the base class CDialog::OnCancel, because it calls EndDialog, which will make the dialog box invisible but will not destroy it. You should also override PostNcDestroy for modeless dialog boxes in order to delete this, since modeless dialog boxes are usually allocated with new. Modal dialog boxes are usually constructed on the frame and do not need PostNcDestroy cleanup.
      

  2.   

    In the case of C++ Windows objects that do perform auto-cleanup, you must call DestroyWindow. If you use operator delete directly, the MFC diagnostic memory allocator will alert you that you are freeing memory twice (the first call to delete as well as the indirect call to "delete this" in the auto-cleanup implementation of PostNcDestroy).因为CFindReplaceDialog(其它的标准对话框不是这样)作自动清除工作,所以必须调用DestroyWindow,由CFindReplaceDialog内部的自动清除工作释放C++对象。
      

  3.   

    CFindReplaceDialog属于GUI对象, 
      应该有自动清除的功能吧,我没有去看它的源码,
    但我稍微看了一下CWinThread的源码,它里面有一成员变量m_bAutoDelete,
    默认时ture,意即自己自动做清理工作,只不知是否可以从核心对象类比到
    GUI对象??
      

  4.   

    to sea_soul (小楼一夜听春雨):
        这么类比是不合适的,对于CWinThread类,MFC的处理思想是不一样,启动一个线程后,希望线程执行完后,可以自行销毁。如果在线程的切换,由主线程做清理工作,为此而做切换的时间有时会觉得没有必要。
        除CFindReplaceDialog外的标准对话框不能作自动清除工作,这是MSDN上说的。所以不要随便用核心对象类比到GUI对象。只能说一般的 C++ Windows objects 提供在PostNcDestroy 里做自动清除的工作。
      

  5.   

    这样应该不会出错吧:
    m_pFindDialog->DestroyWindow()
    delete m_pFindDialog;
    m_pFindDialog = NULL;
      

  6.   

    一般在它的代码中已有如下处理:
    PostNcDestroy()
    {
      delete this;
     }
    所以关闭对话框后,批向它的指针已无效,你只需将你的指针作NULL处理就行了。(以上为本人观点)
     m_pFindDialog=NULL;
      

  7.   

    to In355Hz(好象一条狗):
       如果两次 delete pFindDialog; 你认为妥当吗?所以只能是
    m_pFindDialog->DestroyWindow()
    // 前面已经做过 delete了
    m_pFindDialog = NULL;
      

  8.   

    不管是核心对象,还是GUI对象,是否有自动销毁功能,
    都应看一下源码,这样你甚至可以继承该类,然后修改一些故有的功能,
    为自己编程带来便利,最典型的一个例子就是,
    继承CWinThread类,然后置m_bAutoDelete = FALSE;
    在你做完相应的操作后,再手动销毁,以免线程结束太快,在你相应的操作完成之前就自动销毁了,而造成异常