473,287 Members | 3,240 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

GDI Handle leak when adding a simple Textbox

I have a huge application with lots of custom controls. The app had a
memory leak but fixed that by calling the dispose method where needed
and now the user objects are very stable, when I am looking at the task
manager. But the GDI handles keep growing. I narrowed it down to having
System.Drawing.Font in my custom controls.

To test it out:
I created a simple form with two buttons Add and Remove that - adds and
removes a simple textbox. For this textbox I have created a class that
inherits System.Windows.Forms.UserControl that only has one text box.

Now when the text box doesnot have a Font the GDI handles does not
increase. But when I use the below GDI handles increase:

Me.TextBox1.Font = New System.Drawing.Font("Arial Black", 9.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))

In the Dispose method of this custom control class I have tried this
but the GDI handles keep increasing and after a while (GC) it drops
down, but not to the original number where it started, but with 1 more
than the original GDI count.

Me.TextBox1.Font.FontFamily.Dispose()
Me.TextBox1.Font.Dispose()
Me.TextBox1.Font.FontFamily.Equals(Nothing)
Me.TextBox1.Font = Nothing
Me.TextBox1.Dispose()
I need the text box in a UserControl class because I have lot of custom
controls but with many more controls.

Any help is highly appreciated.

Thanks!

Aug 28 '06 #1
1 5020
Pranil Kanderi wrote:
Now when the text box doesnot have a Font the GDI handles does not
increase. But when I use the below GDI handles increase:

Me.TextBox1.Font = New System.Drawing.Font("Arial Black", 9.0!,
System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point,
CType(0, Byte))
How can it not have a font? When the textbox is first created, does it
not have a default font? When you assign a new font, could the
previous font be hanging around, taking a GDI handle? What if you
disposed the existing font before assigning it?

Me.TextBox1.Font.Dispose()
Me.TextBox1.Font = New System.Drawing.Font(...)

Just a thought.
Me.TextBox1.Font.FontFamily.Equals(Nothing)
By the way, the line above doesn't do anything! The Equals method only
returns a boolean. It doesn't change anything about the FontFamily
object.

Chris

Aug 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jeremy Lemaire | last post by:
Hello, I am working on cross platform code that is displaying a huge memory leak when compiled on 11.00 HPUX using the aCC -AA flag. It is not leaking on NT, LINUX, Solaris, or HPUX without the...
0
by: Kong Li | last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset (9.2.0.5) fixed the handle count leak problem. The problem is in Oracle client component. Thanks. Kong ----- From: Kong...
12
by: Ken Brubaker | last post by:
I am using DB2 8.5 FP5 on Windows 2000 Server and have noticed what appears to be a handle leak. When I execute a DB2 connect statement in a command window, followed by a DB2 connect reset...
4
by: Terry | last post by:
There are a number of things about using unmanaged resources in Windows Forms programming that is unclear to me. In C++, if you loaded an icon resource using "ExtractIcon()", the resource was...
16
by: JCauble | last post by:
We have a large Asp.net application that is currently crashing our production servers. What we are seeing is the aspnet_wp eat up a bunch of memory and then stop unexpectedly. Does not recycle. ...
15
by: Adam J. Schaff | last post by:
I have noticed that if a user closes a form via pressing return (either while the OK button has focus or if AcceptButton is set to OK for the form) then the "ENTER" keypress event fires ON THE...
22
by: Simon | last post by:
Hi all, I have a huge memory leak problem in what is really very simple data insert code. In my app I'm trying to use a typed dataset to insert into a database. It adds quite a few rows (say...
1
by: =?Utf-8?B?QU1lcmNlcg==?= | last post by:
I have a vb.net program that leaks handles as reported by task manager. After running for a couple of hours, task manager reports over 1000 handles, and it continues to grow. I think I am failing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.