tags:

views:

92

answers:

2

I'm trying to debug an error coming out of a Windows .NET based application. The error message goes something like "Error creating window handle". On researching about this error I found out that the likely cause is that the application is using more than 10000 user handles.

I want to put in some debug code into the application and see how many 'user handles' is the application using. But googling for "how to count user handles" didn't help.

So, has anyone of you faced a similar problem? If yes, how did you debug it?

+1  A: 

There are 2 likely causes of this problem in a WinForm app

  1. You are not actively disposing of Control and Form instances in your application. It's harder to hit the problem this way as with a bit of time, the GC will clean up the handles but still posible.
  2. PInvoke into a native API and not closing the resulting handles

Those would be the first 2 places I would check. Another idea would be to go straight to the source and start debugging the handle leak. Here are some links on how to achieve this.

JaredPar
A: 

Another possible cause of this is some control throwing an exception inside OnHandleCreated or the associated HandleCreated event. I believe this can cause errors similar to what you're seeing.

Charlie