|
-
January 29th, 2002, 10:39 AM
#1
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
-
February 5th, 2002, 10:39 AM
#2
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
-
February 6th, 2002, 06:10 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|