473,624 Members | 2,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.UserContr ol 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.Fon t = New System.Drawing. Font("Arial Black", 9.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
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.Fon t.FontFamily.Di spose()
Me.TextBox1.Fon t.Dispose()
Me.TextBox1.Fon t.FontFamily.Eq uals(Nothing)
Me.TextBox1.Fon t = Nothing
Me.TextBox1.Dis pose()
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 5045
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.Fon t = New System.Drawing. Font("Arial Black", 9.0!,
System.Drawing. FontStyle.Regul ar, System.Drawing. GraphicsUnit.Po int,
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.Fon t.Dispose()
Me.TextBox1.Fon t = New System.Drawing. Font(...)

Just a thought.
Me.TextBox1.Fon t.FontFamily.Eq uals(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
4660
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 -AA flag. In another news group I came across some interesting (ok scarey) information regarding memory leaks in the STL list<...> container. I have compiled and executed the following code and verified that this does in fact leak on my system.
0
1386
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 Li (likong@email.com)
12
4006
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 statement, The number of handles displayed in Windows Task Manager for the db2syscs process does not return to its original value, but to 1 handle higher. While this is not a serious issue most of the time, we have applications connecting every 30...
4
3725
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 valid until you called "DestroyIcon()". If you didn't, you had a leak. In C#, I need to load icons from unmanaged programs (.exe, dll) at run time and I want to make sure I'm not leaking resources, but it's not clear to me how to insure that I'm...
16
2381
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. Example: After about 5 hours with a concurrent user base of about 150 users the application raises the aspnet_wp memory usage by almost 500MB. If our server guys modify the web.config this data is released and the workerprocess goes back to a...
15
4033
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 CALLING FORM! This is very bad for me, because in my application, Form1 responds to an ENTER keypress by calling Form2. If the user closes Form2 via an ENTER, then Form1 just reopens it again, kind of trapping the user in Form2 (they can still close...
22
2192
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 hundreds). Unfortunately it has a big ass memory leak and I dont understand why. The code below demonstrates the memory leak. It's like nothing is
1
6761
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 to close or dispose something. I've looked at the code and can't spot the problem. The program is fairly big (10k lines). I can ask it to do something that always increases the handle count, so the problem is reproducible. What I don't know...
0
8231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8168
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8614
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8330
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7153
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6107
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4075
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2603
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1474
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.