Solved

GDI leak?

Posted on 2002-07-11
8
643 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

734 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