Only 10,000 Handles

by Kleinux 25. March 2010 21:27

I find it a little funny that even now that I've been programming Win Forms in C# for five+ years I learn something new that seems so obvious.  In this case I guess I didn't learn something new, but was reminded not to be lazy and dispose of my controls.  Lately at work I've been writing some components that have a lot of variable content.  To display this content I am creating new labels, text boxes, or whatever and when the content is no longer needed those controls are removed.  And when I write removed, that is all I was doing with them.  It turns out it doesn't take long to reach the 10,000 handle limit in Windows and have an application come crashing to a halt.  Before our last release I had discovered where I was doing this and checked in a fix.  Feeling very confident I proclaimed this was the last of that bug to the rest of the department.  Today (while at home babysitting the house as new carpet was installed) I took a look in the logs and found another place I was forgetting to dispose of my dynamic controls.   

So there you go.  Please call Dispose on any controls you are removing when you are not going to reuse said control.  It is true that when the garbage collector reclaims and finalizes your control Dispose is called, the problem is it is easy to have very little memory pressure while still reaching the 10,000 limit of handles.  

Edit:  I do not actually know the upper limit of Handles on windows.  What I meant to write was User Objects.  A process can have up to 10,000 user objects and that is the resource I was running out of in this case.  To be honest I don't really know the difference, but regardless, using that many is bad.

A First Birthday

by Kleinux 16. March 2010 13:28

It is hard to believe that my little boy is turning one today.  It feels like last week I was still putting the finishing touches on his nursery.  In celebration of the day I took the day off work so the family can go to the zoo.  As I write this Milo is still asleep for his morning nap, but when he wakes up we are off.  I'm sure he doesn't understand the concept of a birthday just yet, but he can tell today is something special. He likes when we sing him the happy birthday song.  Amy made some vegan cupcakes from scratch this morning so we have those to look forward too tonight.  For his birthday party this weekend we've ordered a sheetcake for the guests and a special cupcake just for Milo from pattycake.  So enough writing about his birthday and time to get out of here and start to celebrate it!

Tags: , , , , , , , , , , ,

TextBox

RecentPosts