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. GDI Leak in CTreeCtrl with TVS_CHECKBOXES property

GDI Leak in CTreeCtrl with TVS_CHECKBOXES property

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
6 Posts 3 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.
  • B Offline
    B Offline
    bscaer
    wrote on last edited by
    #1

    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?

    H M 2 Replies Last reply
    0
    • B bscaer

      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?

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      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]

      B 1 Reply Last reply
      0
      • B bscaer

        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?

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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

        B 1 Reply Last reply
        0
        • H Hans Dietrich

          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]

          B Offline
          B Offline
          bscaer
          wrote on last edited by
          #4

          The TVSIL_STATE image list is created automatically when the TVS_CHECKBOXES property is set on CTreeCtrl. The image lists contain the images of the checked and unchecked checkboxes.

          1 Reply Last reply
          0
          • M Mark Salsbery

            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

            B Offline
            B Offline
            bscaer
            wrote on last edited by
            #5

            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.

            M 1 Reply Last reply
            0
            • B bscaer

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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

              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