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 due to Memory context

Memory Leak due to Memory context

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresperformancehelptutorialannouncement
9 Posts 2 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.
  • M Offline
    M Offline
    moswal
    wrote on last edited by
    #1

    My application has a serious memory leak problem. It is because I am not able to release the memory consumed by the memory context. In general I save an image in 2 memory context variables. One is used to hold latest data and the other one holds previous data(used for undo purpose). I process the image in the memory context and after processing i display it on the device context. I am reusing the same memory context variables for processing the image. But i believe reusing of memory context causes memory leaks therefore i thought I would the image information in an array. I will process that array and save in the memory context and then display it on the device context. But in order to do this I tried the following ways to release the memory consumed by the memory context. 1) memDC.SelectObject(oldbmp); 2) ReleaseDC(memDC); 3) memDC.DeleteDC(); But i am still facing the memory leak problem. Please confirm if reusing memory context is possible and how to release the memory consumed by the memory context. Thanx in advance. Einstein's Assistant

    C 1 Reply Last reply
    0
    • M moswal

      My application has a serious memory leak problem. It is because I am not able to release the memory consumed by the memory context. In general I save an image in 2 memory context variables. One is used to hold latest data and the other one holds previous data(used for undo purpose). I process the image in the memory context and after processing i display it on the device context. I am reusing the same memory context variables for processing the image. But i believe reusing of memory context causes memory leaks therefore i thought I would the image information in an array. I will process that array and save in the memory context and then display it on the device context. But in order to do this I tried the following ways to release the memory consumed by the memory context. 1) memDC.SelectObject(oldbmp); 2) ReleaseDC(memDC); 3) memDC.DeleteDC(); But i am still facing the memory leak problem. Please confirm if reusing memory context is possible and how to release the memory consumed by the memory context. Thanx in advance. Einstein's Assistant

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      you're creating and deleting the DC over and over ? Why ? I don't see why you could not have a CDC as a member, and I'd suggest your leak is elsewhere, probably to do with the way you handle bitmaps. What OS are you using ? W2000/XP catch GDI leaks for you, and W98 comes with a tool to watch GDI leaks specifically, so you can see if that is what you are leaking. You'll know soon enough, because your whole system will stop drawing stuff ( buttons, windows, etc. ) Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

      M 1 Reply Last reply
      0
      • C Christian Graus

        you're creating and deleting the DC over and over ? Why ? I don't see why you could not have a CDC as a member, and I'd suggest your leak is elsewhere, probably to do with the way you handle bitmaps. What OS are you using ? W2000/XP catch GDI leaks for you, and W98 comes with a tool to watch GDI leaks specifically, so you can see if that is what you are leaking. You'll know soon enough, because your whole system will stop drawing stuff ( buttons, windows, etc. ) Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

        M Offline
        M Offline
        moswal
        wrote on last edited by
        #3

        I am working Win2K. Currently I am not deleting the DCs. I am just reusing the memory context to bitblt the processed output to the screen. I realized that my application has a leak by using windows task manager. And after lot of memory is consumed for pull down menus i just see black box. So I guess it is GDI memory leak. I am not creating and deleting DC over and over again. I just create them once when a image is opened. I.e I call the saveimg method which saves the image in the memory context. I want to release memory used by memory context because I fear that reusing memory context is one of the cause of memory leak. To work around this problem I thought I would copy the pixel color values in an array and then release the memory consumed by the memory context. But unfortunately I am not able to release the memory by any the three methods. Thanx in advance. Einstein's Assistant

        C 1 Reply Last reply
        0
        • M moswal

          I am working Win2K. Currently I am not deleting the DCs. I am just reusing the memory context to bitblt the processed output to the screen. I realized that my application has a leak by using windows task manager. And after lot of memory is consumed for pull down menus i just see black box. So I guess it is GDI memory leak. I am not creating and deleting DC over and over again. I just create them once when a image is opened. I.e I call the saveimg method which saves the image in the memory context. I want to release memory used by memory context because I fear that reusing memory context is one of the cause of memory leak. To work around this problem I thought I would copy the pixel color values in an array and then release the memory consumed by the memory context. But unfortunately I am not able to release the memory by any the three methods. Thanx in advance. Einstein's Assistant

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          moswal wrote: I am working Win2K. Therefore you are not leaking GDI resources - Win2000 will clean them for you, as I said. moswal wrote: I realized that my application has a leak by using windows task manager. And after lot of memory is consumed for pull down menus i just see black box. So I guess it is GDI memory leak. Not under W2000. moswal wrote: But unfortunately I am not able to release the memory by any the three methods. I'm pretty sure that's because you're barking up the wrong tree. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

          M 1 Reply Last reply
          0
          • C Christian Graus

            moswal wrote: I am working Win2K. Therefore you are not leaking GDI resources - Win2000 will clean them for you, as I said. moswal wrote: I realized that my application has a leak by using windows task manager. And after lot of memory is consumed for pull down menus i just see black box. So I guess it is GDI memory leak. Not under W2000. moswal wrote: But unfortunately I am not able to release the memory by any the three methods. I'm pretty sure that's because you're barking up the wrong tree. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

            M Offline
            M Offline
            moswal
            wrote on last edited by
            #5

            But is it true that reusing Memory context object does not cause any memory leak. Thanx in advance Einstein's Assistant

            C 1 Reply Last reply
            0
            • M moswal

              But is it true that reusing Memory context object does not cause any memory leak. Thanx in advance Einstein's Assistant

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #6

              Yes, that is also true, so long as you manage it's state effectively. Either way, the point is that this is not your problem in this case. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

              M 1 Reply Last reply
              0
              • C Christian Graus

                Yes, that is also true, so long as you manage it's state effectively. Either way, the point is that this is not your problem in this case. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002

                M Offline
                M Offline
                moswal
                wrote on last edited by
                #7

                Hi, I am still unable to pin down the source of memory leak. If I upload my source code can u help me to solve the memory leak problem. Thanx a lot in advance. Einstein's Assistant

                C 1 Reply Last reply
                0
                • M moswal

                  Hi, I am still unable to pin down the source of memory leak. If I upload my source code can u help me to solve the memory leak problem. Thanx a lot in advance. Einstein's Assistant

                  C Offline
                  C Offline
                  Christian Graus
                  wrote on last edited by
                  #8

                  Of course. Reask the question as a new post, so others see it too, in case I don't spot the problem. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002

                  M 1 Reply Last reply
                  0
                  • C Christian Graus

                    Of course. Reask the question as a new post, so others see it too, in case I don't spot the problem. Christian I am completely intolerant of stupidity. Stupidity is, of course, anything that doesn't conform to my way of thinking. - Jamie Hale - 29/05/2002 Half the reason people switch away from VB is to find out what actually goes on.. and then like me they find out that they weren't quite as good as they thought - they've been nannied. - Alex, 13 June 2002

                    M Offline
                    M Offline
                    moswal
                    wrote on last edited by
                    #9

                    Hi again, I uploaded my whole application in yahoo's briefcase. Please go through it and help me spot the source of memory leak. Thanks in advance. userid : moswal0071 password : cooldude Einstein's Assistant

                    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