#2
ygp_sfec2010-10-05 21:34
回复 楼主 ygp_sfec
|
下面这段程序在函数中用new操作符动态分配了一块内存,但是任何地方都没有将它删除,按道理应该出现内存泄露才是,但是对内存泄露进行检测,却发现没有出现内存泄露,这是为什么?
void CMainFrame::SwitchView(eView nView)
{
CView* pOldActiveView = GetActiveView();
CView* pNewActiveView = (CView *)GetDlgItem(nView);
if(pNewActiveView == NULL){
switch(nView){
case STRING:
pNewActiveView = (CView *) new CStringView;
break;
case HEX:
pNewActiveView = (CView *) new CHexView;
break;
}
CCreateContext context;
context.m_pCurrentDoc = pOldActiveView->GetDocument();
/*context.m_pCurrentFrame = this;
context.m_pLastView = pOldActiveView;
context.m_pNewViewClass = pOldActiveView->IsKindOf(RUNTIME_CLASS(CStringView))?RUNTIME_CLASS(CStringView):RUNTIME_CLASS(CStringView);*/
pNewActiveView->Create(NULL,NULL,WS_BORDER,CFrameWnd::rectDefault,this,nView,&context);
pNewActiveView->OnInitialUpdate();
}
SetActiveView(pNewActiveView);
//delete pOldActiveView;
pNewActiveView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
pOldActiveView->SetDlgCtrlID(
pOldActiveView->GetRuntimeClass() == RUNTIME_CLASS(CStringView)?STRING:HEX);
pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
RecalcLayout();
}