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. Memory Leak please help

Memory Leak please help

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
8 Posts 4 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.
  • U Offline
    U Offline
    uday kiran janaswamy
    wrote on last edited by
    #1

    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

    P D 2 Replies Last reply
    0
    • U uday kiran janaswamy

      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

      P Offline
      P Offline
      prasad_som
      wrote on last edited by
      #2

      uday kiran janaswamy wrote:

      mC_LibColorBar->mf_GetSelectedLibClrIcon();

      What is mC_LibColorBar ? How icon returned by mf_GetSelectedLibClrIcon() is create ? Function name is really strange.

      Prasad Notifier using ATL | Operator new[],delete[][^]

      U 1 Reply Last reply
      0
      • P prasad_som

        uday kiran janaswamy wrote:

        mC_LibColorBar->mf_GetSelectedLibClrIcon();

        What is mC_LibColorBar ? How icon returned by mf_GetSelectedLibClrIcon() is create ? Function name is really strange.

        Prasad Notifier using ATL | Operator new[],delete[][^]

        U Offline
        U Offline
        uday kiran janaswamy
        wrote on last edited by
        #3

        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

        U 1 Reply Last reply
        0
        • U uday kiran janaswamy

          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

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          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

          U 1 Reply Last reply
          0
          • U uday kiran janaswamy

            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

            U Offline
            U Offline
            uday kiran janaswamy
            wrote on last edited by
            #5

            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

            P 1 Reply Last reply
            0
            • D David Crow

              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

              U Offline
              U Offline
              uday kiran janaswamy
              wrote on last edited by
              #6

              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

              J 1 Reply Last reply
              0
              • U uday kiran janaswamy

                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

                P Offline
                P Offline
                prasad_som
                wrote on last edited by
                #7

                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 using CopyImage. So, use DestroyIcon appropriately in your code.

                Prasad Notifier using ATL | Operator new[],delete[][^]

                1 Reply Last reply
                0
                • U uday kiran janaswamy

                  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

                  J Offline
                  J Offline
                  jhwurmbach
                  wrote on last edited by
                  #8

                  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.

                  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