Results 1 to 10 of 10

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,273

    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,711

    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,176

    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,711

    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,176

    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,512

    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.

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