Tuesday, July 15, 2003

Windows Forms Leak

All Windows Forms that leak two GDI handles. Create a new window, close it, and the GDI handles count in Task Manager is two higher than it was before. The first time you do this it's actually incremented more than two, but that's just some static initialization.

Miki and I found this one last week while chasing some GDI leaks in our code. The problem is that each form has a field named smallIcon of type Icon, and that field is never disposed.

The workaround is to obtain a reference to this private field in the form's Dispose method through reflection and to dispose it and set it to null manually.

I've added this bug as #16 to the .NET Bugs Registry.

   2:33 PM

Content of this site is © Dejan Jelovic. All rights reserved.