A Frame/view/doc question!
-
I want to Create a Frame/view/doc structure On a ActiveX Control,but It will be Found Memory leak! And I Found that the reasons is : CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; How Can I avoid Memroy leak? the Following is My Code : BOOL Create() { if( m_pFrameWnd ) { if( IsWindow(m_pFrameWnd->m_hWnd) ) return TRUE; } CSingleDocTemplate * pDocTemplate; pDocTemplate = new CSingleDocTemplate(IDR_MAPTYPE, RUNTIME_CLASS(CMapDoc), RUNTIME_CLASS(CMapFrame), RUNTIME_CLASS(CMapView)); CMapDoc * pDoc = new CMapDoc; CCreateContext Context; Context.m_pCurrentDoc = pDoc; Context.m_pNewDocTemplate = pDocTemplate; Context.m_pNewViewClass = RUNTIME_CLASS(CMapView); Context.m_pLastView = NULL; Context.m_pCurrentFrame = NULL; CMapFrame * pFrameWnd = new CMapFrame; m_pDoc = pDoc; m_pFrameWnd = pFrameWnd; m_pDocTemplate = pDocTemplate; CRect rcMap; GetClientRect(&rcMap); BOOL ret = m_pFrameWnd->Create(AfxRegisterWndClass(CS_DBLCLKS), NULL, WS_CHILD|WS_VISIBLE, rcMap,this,NULL,&Context); m_pFrameWnd->ShowWindow(SW_SHOW); return ret; } ZHANGYIFEI
-
I want to Create a Frame/view/doc structure On a ActiveX Control,but It will be Found Memory leak! And I Found that the reasons is : CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; How Can I avoid Memroy leak? the Following is My Code : BOOL Create() { if( m_pFrameWnd ) { if( IsWindow(m_pFrameWnd->m_hWnd) ) return TRUE; } CSingleDocTemplate * pDocTemplate; pDocTemplate = new CSingleDocTemplate(IDR_MAPTYPE, RUNTIME_CLASS(CMapDoc), RUNTIME_CLASS(CMapFrame), RUNTIME_CLASS(CMapView)); CMapDoc * pDoc = new CMapDoc; CCreateContext Context; Context.m_pCurrentDoc = pDoc; Context.m_pNewDocTemplate = pDocTemplate; Context.m_pNewViewClass = RUNTIME_CLASS(CMapView); Context.m_pLastView = NULL; Context.m_pCurrentFrame = NULL; CMapFrame * pFrameWnd = new CMapFrame; m_pDoc = pDoc; m_pFrameWnd = pFrameWnd; m_pDocTemplate = pDocTemplate; CRect rcMap; GetClientRect(&rcMap); BOOL ret = m_pFrameWnd->Create(AfxRegisterWndClass(CS_DBLCLKS), NULL, WS_CHILD|WS_VISIBLE, rcMap,this,NULL,&Context); m_pFrameWnd->ShowWindow(SW_SHOW); return ret; } ZHANGYIFEI
This is just a guest, but are you deleting m_pDoc, m_pFrameWnd, m_pDocTemplate when you are finised with them? Normaly, I would put code in the destructor to insure that all allocated member items where freed when the class/object was destroyed. Trust in the code Luke. Yea right!
-
This is just a guest, but are you deleting m_pDoc, m_pFrameWnd, m_pDocTemplate when you are finised with them? Normaly, I would put code in the destructor to insure that all allocated member items where freed when the class/object was destroyed. Trust in the code Luke. Yea right!
sorry ,this can't resolve the proplem! you may try it by yourself!look what happen! ZHANGYIFEI
-
sorry ,this can't resolve the proplem! you may try it by yourself!look what happen! ZHANGYIFEI
Sorry, but there is not enough information for me to fix it. If you have not already, I would recommend you run it through "Bounds Checker" (trail version available). If the memory is allocated in that small piece code you gave then it should be easy to find. Trust in the code Luke. Yea right!