GDI Leak in CTreeCtrl with TVS_CHECKBOXES property
-
When I create a CTreeCtrl with the TVS_CHECKBOXES property and then destroy it, it leaks the GDI objects for the TVSIL_STATE image list. I have tried adding the following code to the OnDestroy function of the CTreeCtrl's parent window. It is called but it doesn't have any affect. // Delete the state image list so it doesn't leak GDI objects // CImageList *pStateImageList = m_Tree.GetImageList(TVSIL_STATE); if (pStateImageList) { m_Tree.SetImageList(NULL, TVSIL_STATE); pStateImageList->DeleteImageList(); } CWnd::OnDestroy(); } Any suggestions on how to fix this GDI leak?
-
When I create a CTreeCtrl with the TVS_CHECKBOXES property and then destroy it, it leaks the GDI objects for the TVSIL_STATE image list. I have tried adding the following code to the OnDestroy function of the CTreeCtrl's parent window. It is called but it doesn't have any affect. // Delete the state image list so it doesn't leak GDI objects // CImageList *pStateImageList = m_Tree.GetImageList(TVSIL_STATE); if (pStateImageList) { m_Tree.SetImageList(NULL, TVSIL_STATE); pStateImageList->DeleteImageList(); } CWnd::OnDestroy(); } Any suggestions on how to fix this GDI leak?
Usually the image list is created as a member variable of some class, so it won't go out of scope. Why are you using pStateImageList?
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]
-
When I create a CTreeCtrl with the TVS_CHECKBOXES property and then destroy it, it leaks the GDI objects for the TVSIL_STATE image list. I have tried adding the following code to the OnDestroy function of the CTreeCtrl's parent window. It is called but it doesn't have any affect. // Delete the state image list so it doesn't leak GDI objects // CImageList *pStateImageList = m_Tree.GetImageList(TVSIL_STATE); if (pStateImageList) { m_Tree.SetImageList(NULL, TVSIL_STATE); pStateImageList->DeleteImageList(); } CWnd::OnDestroy(); } Any suggestions on how to fix this GDI leak?
This should do the same thing....does it work? HIMAGELIST hImgList = TreeView_SetImageList(m_Tree.GetSafeHwnd(), NULL, TVSIL_STATE); if (hImgList) ImageList_Destroy(hImgList); If not, is there a TVSIL_NORMAL imagelist that's not getting destroyed? Mark
Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3
-
Usually the image list is created as a member variable of some class, so it won't go out of scope. Why are you using pStateImageList?
Best wishes, Hans
[CodeProject Forum Guidelines] [How To Ask A Question] [My Articles]
-
This should do the same thing....does it work? HIMAGELIST hImgList = TreeView_SetImageList(m_Tree.GetSafeHwnd(), NULL, TVSIL_STATE); if (hImgList) ImageList_Destroy(hImgList); If not, is there a TVSIL_NORMAL imagelist that's not getting destroyed? Mark
Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3
-
Thanks for the suggestion. I tried it and it did not fix the problem. There is a TVSIL_NORMAL imagelist and it is being destroyed. Also, I used a GDI leak detection program and I could see that it is the checkbox images that are being leaked.
Bummer. I don't have a GDI leak detector but testing with task manager, I get: // Adds 4 GDI Objects m_TreeCtl.ModifyStyle(0, TVS_CHECKBOXES); ... ... // Removes 4 GDI Objects HIMAGELIST hImgList = TreeView_SetImageList(m_TreeCtl.GetSafeHwnd(), NULL, TVSIL_STATE); if (hImgList) ImageList_Destroy(hImgList); I can't find any info documenting a leak. Good luck! Mark
Mark Salsbery Microsoft MVP - Visual C++ This episode brought to you by the number 3