Results 1 to 12 of 12

Thread: [RESOLVED] DeleteObject API for gdi32

  1. #1

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    822

    Resolved [RESOLVED] DeleteObject API for gdi32

    I am using a gdi32 api. Specifically CreateRoundRectRgn.

    I have learned that you should clean up after you use it. The way is to use DeleteObject.

    I would like to know.
    What happens if you do not cleanup? What are the symptoms? Is it just proper programming? Or, does something happen to the system? It seems I can close a program without executing the DeleteObject API.

    When I use it, how do I know it worked properly?

    Thanks

  2. #2
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    6,636

    Re: DeleteObject API for gdi32

    It's just a small memory leak if you don't clean it up properly.

  3. #3

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    822

    Re: DeleteObject API for gdi32

    If I close the program, without running DeleteObject, does the leak go away? If yes, than why bother to run DeleteObject?

  4. #4
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,806

    Re: DeleteObject API for gdi32

    Quote Originally Posted by AccessShell View Post
    If I close the program, without running DeleteObject, does the leak go away? If yes, than why bother to run DeleteObject?
    For starters the longer your programme runs the larger the leak will be and you will potentially encounter problems if you leak too many resources.

    However, deliberately creating resources and not correctly cleaning up afterwards is just bad programming practice. It is a bad habit to get into and I would honestly question the quality of any other code that was written by someone who didn't do something as basic as cleaning up resources.

  5. #5

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    822

    Re: DeleteObject API for gdi32

    I understand the "good programming practice". But, the leaks occur while the programming is running. A Google search for 'memory leaks' gives this

    "Is there any way to fix memory leak?

    The best way to fix memory leaks in Windows is by closing the program and processes that are eating up the most memory. Press CTRL + Shift + Esc key together to launch Task Manager. Click on the Processes and find the program using most memory from the list. Click on EndTask to close the program."

    This tells me that while the program is running, I produce the memory leak. When the program ends, DeleteObject, or not, the memory leak is fixed. I cannot prevent the leak when the program is running, when it ost important

    What am my missing?

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,335

    Re: DeleteObject API for gdi32

    What you are missing is that you should prevent memory leaks in your program.
    The facts that Windows is able to clean up the mess after your program terminates doesn't mean you are not responsible for the program behavior.

  7. #7

    Thread Starter
    Fanatic Member AccessShell's Avatar
    Join Date
    Oct 2013
    Posts
    822

    Re: DeleteObject API for gdi32

    I understand the last post. Therefore, it is not possible to prevent the leaks while the program is executing???

  8. #8
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,806

    Re: DeleteObject API for gdi32

    Quote Originally Posted by AccessShell View Post
    I understand the last post. Therefore, it is not possible to prevent the leaks while the program is executing???
    You prevent the leaks by deleting the objects once you are no longer using them. You only get a leak if you are creating the objects and not deleting them when you have finished with them.

  9. #9
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,335

    Re: DeleteObject API for gdi32

    I don't understand what you want at all
    Quote Originally Posted by AccessShell View Post
    ..
    I have learned that you should clean up after you use it. The way is to use DeleteObject.
    ..
    The reason for using DeleteObject is explained.
    Then you ask why should you clean up when the OS does also cleaning up.
    We explain why you get memory leaks in your application.

    And your response:
    Quote Originally Posted by AccessShell View Post
    I understand the last post. Therefore, it is not possible to prevent the leaks while the program is executing???
    Yes, when you use DeleteObject you should not have memory leaks..

  10. #10
    PowerPoster yereverluvinuncleber's Avatar
    Join Date
    Feb 2014
    Location
    Norfolk UK (inbred)
    Posts
    2,820

    Re: [RESOLVED] DeleteObject API for gdi32

    I understand the last post. My house has leaks in my roof when it rains but I find out that if I demolish the house I have no leaks.

    How do I fix the leaks when I have demolished my house?

    I understand everything including all the posts.
    https://github.com/yereverluvinunclebert

    Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.

    By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.

  11. #11
    New Member
    Join Date
    Dec 2024
    Posts
    1

    Re: [RESOLVED] DeleteObject API for gdi32

    If you leak one resource, one time, no big deal. But if your program is leaking that that one resource dozens, hundreds, or thousands of times, you will finally understand that it is a big deal because your program will crash and likely you'll crash Windows and need to reboot.

  12. #12
    Hyperactive Member HackerVlad's Avatar
    Join Date
    Nov 2023
    Posts
    467

    Re: [RESOLVED] DeleteObject API for gdi32

    I used to foolishly think that it was not necessary to free up resources for myself. I don't even remember before I understood why to perform, for example, the CloseHandle function if the program is already working fine without this execution. Oh, how stupid I used to be, a long time ago, when I was just starting to program

    It is absolutely necessary to free up memory for yourself. This should be remembered by any beginner once and for all. And don't be lazy to clean different objects after yourself, unless it happens automatically, of course.

    I'll give you an example from my life. I used to load icons using the ExtractIconEx function and draw them in my program menu. And I thought that this would be enough, and I did not execute DestroyIcon after the menu was completed. Moreover, every time I downloaded new icons (also stupidly, although it's enough to load only once and remember). And what do you think happened in the end? If the menu was opened only a few times, then nothing happened. But if the menu was opened hundreds of times, then the memory leak had already made itself felt, and then the miracles began: the graphics became terribly buggy, the program stopped drawing any icons at all, even in the VB6 IDE itself, the drawing of all icons and all graphics was distorted. That's what a memory leak and failure to perform a simple DestroyIcon function led to.

    So always be sure to clean up your memory, close handles, delete objects, and always, always clean up your trash. It is very important.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width