BOOL CSyxPosApp::InitInstance()
{
...
CMainFrame* pFrame = new CMainFrame;
m_pMainWnd = pFrame; // create and load the frame with its resources pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); // The one and only window has been initialized, so show and update it.
pFrame->ShowWindow(SW_SHOW);
pFrame->UpdateWindow(); return TRUE;
}内存泄露,DEBUG信息中提示就是CMainFrame* pFrame = new CMainFrame;这条语句引起的,请问如何释放pFrame申请的内存和资源?我这样修改了,好像不行:int CSyxPosApp::ExitInstance() 
{
// TODO: Add your specialized code here and/or call the base class
delete m_pMainWnd; return CWinApp::ExitInstance();
}
请大家帮忙指点一下!

解决方案 »

  1.   

    delete m_pMainWnd;
    为什么不行呢?是不是类型不对,一个MainWnd,一个MainFrame?
      

  2.   

    在delete m_pMainWnd;下面再加一句
    pFrame = NULL;试试看
      

  3.   

    CMainFrame* pFrame = new CMainFrame;这样做有问题的, APP的初始化应该这样:
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
    IDR_MAINFRAME,
    RUNTIME_CLASS(CXXXDoc),
    RUNTIME_CLASS(CMainFrame),       // main SDI frame window
    RUNTIME_CLASS(CXXXView));
    AddDocTemplate(pDocTemplate);//CSingleDcoTemplate会初始化CMainFrame类的成员m_pMainWnd, 然后再进行后面的操作:
    // The one and only window has been initialized, so show and update it.
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();也就是说你的初始化错误了
      

  4.   

    是啊,你那个应该是用向导直接生成没有修改过的代码。我给你看的代码是别人写的代码,他的原意是在框架的OnCreate函数中来调用他的一些线程函数(或者说他把CFrame::OnCreate()函数当作入口点),他实际上是不需要文档界面的。他的使用用的不规范,他创建的程序是单文档的,但实际做的效果却是对话框。他的功能是程序启动完后启动一个线程,这个线程循环检测有没有磁卡插入打印机,如果有则弹出一个对话框界面进行操作选择。换句话说,如何在单文档中只使用框架而不关联文档?即如何动态创建框架?创建后如何释放相应的资源?谢谢!!