Solved

GDI leak?

Posted on 2002-07-11
8
637 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
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…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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