Memory Leak please help
-
Dear All, I am getting a Memory Leak. I am giving the Seniario. Code. //======================================================================= CPictureHolder pic; HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); //Get An Icon and store in hIconToDraw. pic.CreateFromIcon(hIconToDraw); //======================================================================= The Statement "HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); will load an Icon. But there is a Memory Leak how can i Resolve this. Urgent pls help me out. //=======================================================================
Uday kiran
-
Dear All, I am getting a Memory Leak. I am giving the Seniario. Code. //======================================================================= CPictureHolder pic; HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); //Get An Icon and store in hIconToDraw. pic.CreateFromIcon(hIconToDraw); //======================================================================= The Statement "HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); will load an Icon. But there is a Memory Leak how can i Resolve this. Urgent pls help me out. //=======================================================================
Uday kiran
uday kiran janaswamy wrote:
mC_LibColorBar->mf_GetSelectedLibClrIcon();
What is
mC_LibColorBar
? How icon returned bymf_GetSelectedLibClrIcon()
is create ? Function name is really strange.Prasad Notifier using ATL | Operator new[],delete[][^]
-
uday kiran janaswamy wrote:
mC_LibColorBar->mf_GetSelectedLibClrIcon();
What is
mC_LibColorBar
? How icon returned bymf_GetSelectedLibClrIcon()
is create ? Function name is really strange.Prasad Notifier using ATL | Operator new[],delete[][^]
Hi Prasad, The Statement "mC_LibColorBar->mf_GetSelectedLibClrIcon();" will return the ICon. how can i delete that ICon, if i am trying to delete that Icon Handle then Asserion is comming. If i dont delete then a Memory Leak is comming.
Uday kiran
-
Dear All, I am getting a Memory Leak. I am giving the Seniario. Code. //======================================================================= CPictureHolder pic; HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); //Get An Icon and store in hIconToDraw. pic.CreateFromIcon(hIconToDraw); //======================================================================= The Statement "HICON hIconToDraw = mC_LibColorBar->mf_GetSelectedLibClrIcon(); will load an Icon. But there is a Memory Leak how can i Resolve this. Urgent pls help me out. //=======================================================================
Uday kiran
uday kiran janaswamy wrote:
But there is a Memory Leak...
How are you verifying this?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Hi Prasad, The Statement "mC_LibColorBar->mf_GetSelectedLibClrIcon();" will return the ICon. how can i delete that ICon, if i am trying to delete that Icon Handle then Asserion is comming. If i dont delete then a Memory Leak is comming.
Uday kiran
Hi Prasad, The Code i am giving will get you clear picture. //==================================================== HICON CGTD2to32ColorWnd::mf_GetSelectedLibClrIcon() { return mf_GetLibClrIcon(mui_ColorSelected); } //===================================================== which inturn calls this function //===================================================== HICON CGTD2to32ColorWnd::mf_GetLibClrIcon(long pl_LibClr) { CImageList *lpi_LibToolbarImageList = NULL; HICON lH_Icon = NULL; HICON lH_ReturnedIcon = NULL; // Get the Toolbar internal imagelist. if(pl_LibClr == ID_NOCOLOR_SELECTED && mb_ShowAllColorButton) { lpi_LibToolbarImageList = mC_wndAllColorToolBar.GetToolBarCtrl().GetImageList(); } else { lpi_LibToolbarImageList = mC_wndColorToolBar.GetToolBarCtrl().GetImageList(); } int li_BtnIdx = mf_GetLibButtonIndex(pl_LibClr); // Extract the HICON from the toolbar's Image list for the currently selected // Patten and return the same. if(lpi_LibToolbarImageList) { lH_Icon=lpi_LibToolbarImageList->ExtractIcon(li_BtnIdx); // Copies the lH_PattrenIcon into lH_ReturnedIcon and deletes the lH_PattrenIcon. lH_ReturnedIcon = (HICON)(::CopyImage(lH_Icon,IMAGE_ICON,0,0,LR_COPYDELETEORG)); lH_Icon = NULL; } // Retrun the copied Icon. return lH_ReturnedIcon; } //===================================================== in short it will Copy the Icon using lH_ReturnedIcon = (HICON)(::CopyImage(lH_Icon,IMAGE_ICON,0,0,LR_COPYDELETEORG)); and Return the Icon Handle
Uday kiran
-
uday kiran janaswamy wrote:
But there is a Memory Leak...
How are you verifying this?
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
Hi David, In the Windows Task Manager GDI Objects. 1) i am clicking the Process Tab so i am getting the GDI Objects. where the Leak is Showing Clearly. Please help me out.
Uday kiran
-
Hi Prasad, The Code i am giving will get you clear picture. //==================================================== HICON CGTD2to32ColorWnd::mf_GetSelectedLibClrIcon() { return mf_GetLibClrIcon(mui_ColorSelected); } //===================================================== which inturn calls this function //===================================================== HICON CGTD2to32ColorWnd::mf_GetLibClrIcon(long pl_LibClr) { CImageList *lpi_LibToolbarImageList = NULL; HICON lH_Icon = NULL; HICON lH_ReturnedIcon = NULL; // Get the Toolbar internal imagelist. if(pl_LibClr == ID_NOCOLOR_SELECTED && mb_ShowAllColorButton) { lpi_LibToolbarImageList = mC_wndAllColorToolBar.GetToolBarCtrl().GetImageList(); } else { lpi_LibToolbarImageList = mC_wndColorToolBar.GetToolBarCtrl().GetImageList(); } int li_BtnIdx = mf_GetLibButtonIndex(pl_LibClr); // Extract the HICON from the toolbar's Image list for the currently selected // Patten and return the same. if(lpi_LibToolbarImageList) { lH_Icon=lpi_LibToolbarImageList->ExtractIcon(li_BtnIdx); // Copies the lH_PattrenIcon into lH_ReturnedIcon and deletes the lH_PattrenIcon. lH_ReturnedIcon = (HICON)(::CopyImage(lH_Icon,IMAGE_ICON,0,0,LR_COPYDELETEORG)); lH_Icon = NULL; } // Retrun the copied Icon. return lH_ReturnedIcon; } //===================================================== in short it will Copy the Icon using lH_ReturnedIcon = (HICON)(::CopyImage(lH_Icon,IMAGE_ICON,0,0,LR_COPYDELETEORG)); and Return the Icon Handle
Uday kiran
uday kiran janaswamy wrote:
// Copies the lH_PattrenIcon into lH_ReturnedIcon and deletes the lH_PattrenIcon. lH_ReturnedIcon = (HICON)(::CopyImage(lH_Icon,IMAGE_ICON,0,0,LR_COPYDELETEORG)); lH_Icon = NULL
You need to use
DestroyIcon
to free memory for icon created by usingCopyImage
. So, useDestroyIcon
appropriately in your code.Prasad Notifier using ATL | Operator new[],delete[][^]
-
Hi David, In the Windows Task Manager GDI Objects. 1) i am clicking the Process Tab so i am getting the GDI Objects. where the Leak is Showing Clearly. Please help me out.
Uday kiran
uday kiran janaswamy wrote:
so i am getting the GDI Objects. where the Leak is Showing Clearly.
So instead of a memory-leak you have a GDI-resource-leak. Also, you did not read the docs to ::CopyIcon. What hindered you? --fixed typo
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation." -- Caius Petronius, Roman Consul, 66 A.D.