Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Why,Why,Why no one can resolvoe this Question?Doc/view/frame!I Have post this artical 5 time!

Why,Why,Why no one can resolvoe this Question?Doc/view/frame!I Have post this artical 5 time!

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomperformance
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zhangyifei
    wrote on last edited by
    #1

    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 ZHANGYIFEI

    K M H 3 Replies Last reply
    0
    • Z 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 ZHANGYIFEI

      K Offline
      K Offline
      KarstenK
      wrote on last edited by
      #2

      Solve the problem yourself: Trace every object you create and you find your leak. (You even didn´t mentioned the leak X| ) Try this @ home. (B&B)

      1 Reply Last reply
      0
      • Z 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 ZHANGYIFEI

        M Offline
        M Offline
        Mike Upton
        wrote on last edited by
        #3

        If nobody could answer it the first time, nobody can answer it after 5 times, 50 times, or 500 times. The only thing posting it more often will achieve is making everybody here less likely to read any of your questions in the future. The only thing that might help us give you an answer is if you provide more information, not just repost the same thing. For example, which objects leak, what is the Create function a member of... Oh, and learn what the <pre> tag does, it'll make reading your code a lot easier for the rest of us, and that might also help you get an answer. I promise you that spamming the board won't.


        "We are the knights who say Ni" (The Knights Who Say Ni)

        1 Reply Last reply
        0
        • Z 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 ZHANGYIFEI

          H Offline
          H Offline
          Harrier
          wrote on last edited by
          #4

          Why, it's the simplicity of the problem. Do the easy things first rather than getting wrapped up in a complicated solution. I see two (2) operator new()'s, where are the corresponding delete's. You haven't discussed this. I assume the example code resides in an object. If you allocate memory off the heap you are responsible for freeing that memory, say in the object's destructor. Describe what you've done to resolve the problem, what objects are being leaked, where you try to release them, etc. There's not enough information to resolve your issue.

          J 1 Reply Last reply
          0
          • H Harrier

            Why, it's the simplicity of the problem. Do the easy things first rather than getting wrapped up in a complicated solution. I see two (2) operator new()'s, where are the corresponding delete's. You haven't discussed this. I assume the example code resides in an object. If you allocate memory off the heap you are responsible for freeing that memory, say in the object's destructor. Describe what you've done to resolve the problem, what objects are being leaked, where you try to release them, etc. There's not enough information to resolve your issue.

            J Offline
            J Offline
            John R Shaw
            wrote on last edited by
            #5

            I gave basicaly the same answer 2 days ago, on the 1st post (I think). If he cann't use that or the suggestion I gave him on my replay to his reply. Then forget it. Trust in the code Luke. Yea right!

            Z 1 Reply Last reply
            0
            • J John R Shaw

              I gave basicaly the same answer 2 days ago, on the 1st post (I think). If he cann't use that or the suggestion I gave him on my replay to his reply. Then forget it. Trust in the code Luke. Yea right!

              Z Offline
              Z Offline
              zhangyifei
              wrote on last edited by
              #6

              the proplem look easy !but not, and not "new->delete" so easy!why don't try it by yourself ,look what happen! the code i have offer! I have delete all,but Can't avoid leaks,the reason is MFC two static data member,and this two member is internal use!! ZHANGYIFEI

              J 1 Reply Last reply
              0
              • Z zhangyifei

                the proplem look easy !but not, and not "new->delete" so easy!why don't try it by yourself ,look what happen! the code i have offer! I have delete all,but Can't avoid leaks,the reason is MFC two static data member,and this two member is internal use!! ZHANGYIFEI

                J Offline
                J Offline
                John R Shaw
                wrote on last edited by
                #7

                :(I've said before that this is not enough imformation for me to solve the problem. By the looks of things I would need the project, all any of us can do is make sugestions on possible solutions. The rest is up to you. // These values are inialized in APPCORE.CPP // If this is part of your code I am supprised // you did not get a multiple definition errors. CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; Complete list of source files associated with CDocManager: AFXWIN.H, APPCODE.CPP, APPUI2.CPP, DLLINIT.CPP, DOCMGR.CPP, DOCMULTI.CPP, DOCTEMPL.CPP No one ever said debbuging was easy!

                Z 1 Reply Last reply
                0
                • J John R Shaw

                  :(I've said before that this is not enough imformation for me to solve the problem. By the looks of things I would need the project, all any of us can do is make sugestions on possible solutions. The rest is up to you. // These values are inialized in APPCORE.CPP // If this is part of your code I am supprised // you did not get a multiple definition errors. CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; Complete list of source files associated with CDocManager: AFXWIN.H, APPCODE.CPP, APPUI2.CPP, DLLINIT.CPP, DOCMGR.CPP, DOCMULTI.CPP, DOCTEMPL.CPP No one ever said debbuging was easy!

                  Z Offline
                  Z Offline
                  zhangyifei
                  wrote on last edited by
                  #8

                  CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; those two member is not in my code ,those in MFC code ! I said that those two member appear memory leak! BOOL Create() //in ActiveX OnCreate Event perform this function! { 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)); // pDocTemplate in destructor function delete this! CMapDoc * pDoc = new CMapDoc;// in destructor function delete this! 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;// in destructor function delete this! 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; } //note : CMapDoc inherit from COleDocument ; CMapView inherit from CScrollView ; CMainFrame inherit from CFrameWnd ; I don't have CDocManager and it's derive class! debug output : Detected memory leaks! Dumping objects -> plex.cpp(31) : {72} normal block at 0x01402F70, 124 bytes long. Data: < @ > 00 00 00 00 00 00 00 00 00 00 00 00 00 11 40 01 doctempl.cpp(64) : {71} client block at 0x01401060, subtype 0, 32 bytes long. a CDocManager object at $01401060, 32 bytes long doctempl.cpp(62) : {70} client block at 0x014010B0, subtype 0, 28 bytes long. a CPtrList object at $014010B0, 28 bytes long ZHANGYIFEI

                  J 1 Reply Last reply
                  0
                  • Z zhangyifei

                    CDocManager* CDocManager::pStaticDocManager; CPtrList* CDocManager::pStaticList; those two member is not in my code ,those in MFC code ! I said that those two member appear memory leak! BOOL Create() //in ActiveX OnCreate Event perform this function! { 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)); // pDocTemplate in destructor function delete this! CMapDoc * pDoc = new CMapDoc;// in destructor function delete this! 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;// in destructor function delete this! 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; } //note : CMapDoc inherit from COleDocument ; CMapView inherit from CScrollView ; CMainFrame inherit from CFrameWnd ; I don't have CDocManager and it's derive class! debug output : Detected memory leaks! Dumping objects -> plex.cpp(31) : {72} normal block at 0x01402F70, 124 bytes long. Data: < @ > 00 00 00 00 00 00 00 00 00 00 00 00 00 11 40 01 doctempl.cpp(64) : {71} client block at 0x01401060, subtype 0, 32 bytes long. a CDocManager object at $01401060, 32 bytes long doctempl.cpp(62) : {70} client block at 0x014010B0, subtype 0, 28 bytes long. a CPtrList object at $014010B0, 28 bytes long ZHANGYIFEI

                    J Offline
                    J Offline
                    John R Shaw
                    wrote on last edited by
                    #9

                    Open appcore.cpp and look at CWinApp::~CWinApp(), this is where CDocManager::pStaticList and CDocManager::pStaticDocManager are deleted. Since CWinApp is not the base class for your project then these two pointers will not be deleted. Therefore, you must delete them your self. I beleive that the plex.cpp memory leak should go away when you fix the other two, because it is used to allocate storage for nodes and CDocManager uses a list of nodes used to store the docment template pointers. Note also, that the list of memory leaks is the inverse of the order of allocations. 1) CPtrList is allocated. 2) CDocManager is allocated. 3) CPlex alloction occurs (CDocManager::pStaticList->AddTail(this)). :-OThanks for the dump, it made the answer ovious where the problem was. Blast I should have seen this earlier!!!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups