-
Sep 3rd, 2024, 02:01 PM
#1
Thread Starter
Fanatic Member
[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
-
Sep 3rd, 2024, 10:03 PM
#2
Re: DeleteObject API for gdi32
It's just a small memory leak if you don't clean it up properly.
-
Sep 4th, 2024, 10:19 AM
#3
Thread Starter
Fanatic Member
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?
-
Sep 4th, 2024, 10:24 AM
#4
Re: DeleteObject API for gdi32
Originally Posted by AccessShell
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.
-
Sep 4th, 2024, 11:10 AM
#5
Thread Starter
Fanatic Member
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?
-
Sep 5th, 2024, 04:05 AM
#6
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.
-
Sep 5th, 2024, 08:15 AM
#7
Thread Starter
Fanatic Member
Re: DeleteObject API for gdi32
I understand the last post. Therefore, it is not possible to prevent the leaks while the program is executing???
-
Sep 5th, 2024, 09:31 AM
#8
Re: DeleteObject API for gdi32
Originally Posted by AccessShell
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.
-
Sep 5th, 2024, 09:47 AM
#9
Re: DeleteObject API for gdi32
I don't understand what you want at all
Originally Posted by AccessShell
..
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:
Originally Posted by AccessShell
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..
-
Sep 6th, 2024, 04:10 AM
#10
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|