CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2000
    Location
    Romania, Cluj-Napoca
    Posts
    57

    MEMORY LEAKS USING CImageList

    I was building an application using a CListCtrl control. I was embedded into the class (derived from CDialog), a member of type CImageList.
    Then, in the OnInitDialog handler, I was added the following code:

    m_ListImages.Create(16,16,ILC_COLOR,2,0);

    m_ListImages.SetBkColor(RGB(255,255,255));
    m_ListImages.Add(::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_OFF)));
    m_ListImages.Add(::LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDI_ON)));
    m_List.SetImageList(&m_ListImages,LVSIL_SMALL);



    Everything goes fine, but then I was tested this application with the BoundsChecker, and I get 68 bytes memory leaks in winctrl2.cpp line 943.
    Below is the code where the error occured

    static CHandleMap* afxMapHIMAGELIST(BOOL bCreate = FALSE);

    static CHandleMap* afxMapHIMAGELIST(BOOL bCreate)
    {
    AFX_MODULE_THREAD_STATE* pState = AfxGetModuleThreadState();
    if (pState->m_pmapHIMAGELIST == NULL && bCreate)
    {
    BOOL bEnable = AfxEnableMemoryTracking(FALSE);
    #ifndef _AFX_PORTABLE
    _PNH pnhOldHandler = AfxSetNewHandler(&AfxCriticalNewHandler);
    #endif
    pState->m_pmapHIMAGELIST = new CHandleMap(RUNTIME_CLASS(CImageList),
    offsetof(CImageList, m_hImageList)); -> HERE I GET THE MEMORY LEAK

    #ifndef _AFX_PORTABLE
    AfxSetNewHandler(pnhOldHandler);
    #endif
    AfxEnableMemoryTracking(bEnable);
    }
    return pState->m_pmapHIMAGELIST;
    }



    Does anybody has a clue about this ?
    I was trying to delete all the images at application exit, but in vain.


    10x in advance


  2. #2
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: MEMORY LEAKS USING CImageList

    Are you deleting your CHandleMap anywhere? (e.g. delete pState->m_pmapHIMAGELIST; )

    "A problem well stated is a problem half solved.” - Charles F. Kettering

  3. #3
    Join Date
    Apr 2000
    Location
    Romania, Cluj-Napoca
    Posts
    57

    Re: MEMORY LEAKS USING CImageList

    Do I really need to do this ?
    Normally I should not care about this, cause MFC must clean-it, and in MSDN says that everything is cleaned by the destructor.
    10x anyway
    If I will get more answers I will let U know


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured