|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
GDI Handle leak when adding a simple Textboxmemory 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! Pranil Kanderi wrote:
> Now when the text box doesnot have a Font the GDI handles does not How can it not have a font? When the textbox is first created, does it> 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)) 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 onlyreturns a boolean. It doesn't change anything about the FontFamily object. Chris
Timer driving me nuts
Tree List View OK, new registry question vfp oledbcommand [Fail] Resource and Time consuming stuff Listview - get value multiple columns validating textbox Virtual desktop makes .NET modal dialog panels disappear How do I add a c++ library to my vb.net project? looking for tree/outline control that allows in-place editing AND will expand as I type |
|||||||||||||||||||||||