Solved

GDI leak?

Posted on 2002-07-11
8
646 Views
Last Modified: 2013-12-03
Hi,

I use this code under Windows 2000:

HBRUSH hBrushTest;
hBrushTest = CreateSolidBrush( RGB(0,0,0) );
DeleteObject( hBrushTest );

After the creation of the brush, the GDI count in the task manager (when you show that column) increases by one. Unfortunately, the count doesn't decrease after the deletion of the brush.

What's wrong with this picture???
0
Comment
Question by:mahtieubrault
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 32

Expert Comment

by:jhance
ID: 7147943
I don't think that proves a leak.  What if you do:

HBRUSH hBrushTest;

for(int i=0; i<1000; i++){
  hBrushTest = CreateSolidBrush( RGB(0,0,0) );
  DeleteObject( hBrushTest );
}

Does your resource count decrease by 1000?  I think not.
0
 
LVL 12

Expert Comment

by:pjknibbs
ID: 7148455
I wonder if Windows is being a bit clever here. The brush you're creating there is identical to what you'd get if you did a GetStockObject(BLACK_BRUSH), so maybe Windows is actually setting up and returning the default object?
0
 

Author Comment

by:mahtieubrault
ID: 7148910
By doing the loop 1000 times, it increases the GDI count by 10. And it won't be cleared until the application is closed.  If it's in a dialog that's going to be used only once, I don't want the resources to stay in memory after using the dialog.

Any idea?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 1

Expert Comment

by:charlass
ID: 7149077
The good news is however, never the mind how many times you are running this loop (I did it until 30.000) the GDI handle count just climbs up by 10. But you are right, it is quite strange.
0
 
LVL 32

Expert Comment

by:jhance
ID: 7149319
>>I don't want the resources to stay in memory after using the dialog.

Then don't allocate them.  You DO NOT have direct control over how or when Windows manages its resources.  As long as you "clean up" every object you create, you won't leak terminally.  Windows caches object store in the assumption that it will likely be reused before the app exits.

If you don't want ANY resources used, then don't allocate any, but, of course, that generally results in a useless application.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 10787458
PAQed - no points refunded (of 200)

modulo
Community Support Moderator
0

Featured Post

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question