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. LoadImage() memory leak.

LoadImage() memory leak.

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
13 Posts 5 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.
  • N Offline
    N Offline
    Neha
    wrote on last edited by
    #1

    Hi, In my application i have this: HBITMAP hImage; hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION ); DeleteObject(hImage); These statement will increase the memory usage by 28 KB. Size of the "temp.bmp" file is 360KB. Could any one tell me why is it so? Regards Neha

    D A A M 4 Replies Last reply
    0
    • N Neha

      Hi, In my application i have this: HBITMAP hImage; hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION ); DeleteObject(hImage); These statement will increase the memory usage by 28 KB. Size of the "temp.bmp" file is 360KB. Could any one tell me why is it so? Regards Neha

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

      Neha wrote: These statement will increase the memory usage by 28 KB. How are you measuring this?


      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

      N 1 Reply Last reply
      0
      • N Neha

        Hi, In my application i have this: HBITMAP hImage; hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION ); DeleteObject(hImage); These statement will increase the memory usage by 28 KB. Size of the "temp.bmp" file is 360KB. Could any one tell me why is it so? Regards Neha

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        this is not the answer to your question, but for loading a bitmap from the disk, you dont need to pass the hInst to the function! Don't try it, just do it! ;-)

        N 1 Reply Last reply
        0
        • D David Crow

          Neha wrote: These statement will increase the memory usage by 28 KB. How are you measuring this?


          Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

          N Offline
          N Offline
          Neha
          wrote on last edited by
          #4

          Using window task manager mem usage for that application.

          A D 2 Replies Last reply
          0
          • A Alexander M

            this is not the answer to your question, but for loading a bitmap from the disk, you dont need to pass the hInst to the function! Don't try it, just do it! ;-)

            N Offline
            N Offline
            Neha
            wrote on last edited by
            #5

            Still no difference.. One more strange thing is when some of function been called, It will increase the memory usage by 4KB.Those function don't allocate anything......

            D 1 Reply Last reply
            0
            • N Neha

              Using window task manager mem usage for that application.

              A Offline
              A Offline
              Alexander M
              wrote on last edited by
              #6

              the value displayed in the task manager is not correct at all! Don't try it, just do it! ;-)

              N 1 Reply Last reply
              0
              • A Alexander M

                the value displayed in the task manager is not correct at all! Don't try it, just do it! ;-)

                N Offline
                N Offline
                Neha
                wrote on last edited by
                #7

                Is there any proof for that?

                1 Reply Last reply
                0
                • N Neha

                  Using window task manager mem usage for that application.

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

                  The best you could hope to come from TM is to show the size of the address space that is in use, not the amount of that address space that your program is actually using. Perhaps you are confusing address space with program size.


                  Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                  N 1 Reply Last reply
                  0
                  • N Neha

                    Still no difference.. One more strange thing is when some of function been called, It will increase the memory usage by 4KB.Those function don't allocate anything......

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

                    Neha wrote: One more strange thing is when some of function been called, It will increase the memory usage by 4KB.Those function don't allocate anything...... How do you know? When you call a function that is not your own, are you sure of what it does, or doesn't do, behind the scene?


                    Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                    1 Reply Last reply
                    0
                    • D David Crow

                      The best you could hope to come from TM is to show the size of the address space that is in use, not the amount of that address space that your program is actually using. Perhaps you are confusing address space with program size.


                      Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

                      N Offline
                      N Offline
                      Neha
                      wrote on last edited by
                      #10

                      I am talking about the Mem usage column in the processes tab. I think this represents the memory usage by the application.

                      1 Reply Last reply
                      0
                      • N Neha

                        Hi, In my application i have this: HBITMAP hImage; hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION ); DeleteObject(hImage); These statement will increase the memory usage by 28 KB. Size of the "temp.bmp" file is 360KB. Could any one tell me why is it so? Regards Neha

                        A Offline
                        A Offline
                        antlers
                        wrote on last edited by
                        #11

                        If you execute that code 100 times does it increase the memory in task manager by 2800 K? If yes, then it is a memory leak. If no, it is just increasing the process address space one time to reflect the additional library code you used.

                        N 1 Reply Last reply
                        0
                        • A antlers

                          If you execute that code 100 times does it increase the memory in task manager by 2800 K? If yes, then it is a memory leak. If no, it is just increasing the process address space one time to reflect the additional library code you used.

                          N Offline
                          N Offline
                          Neha
                          wrote on last edited by
                          #12

                          Yes,It increases by 2800K........

                          1 Reply Last reply
                          0
                          • N Neha

                            Hi, In my application i have this: HBITMAP hImage; hImage = (HBITMAP)::LoadImage (AfxGetInstanceHandle(), "c:\\TEMP.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE |LR_CREATEDIBSECTION ); DeleteObject(hImage); These statement will increase the memory usage by 28 KB. Size of the "temp.bmp" file is 360KB. Could any one tell me why is it so? Regards Neha

                            M Offline
                            M Offline
                            melwyn
                            wrote on last edited by
                            #13

                            Write a program that doesn't do anything main() { return 0; } Now see how much memory this takes in task mgr. According to you it shud take 0 bytes!!

                            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