handle leak



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 is how to go about finding what is wrong. For example,
I'd like to know what kind of handles task manager is talking about. Are
they file handles, fonts, or what? I'd like to snapshot the handles, take an
action that raises the handle count, and then find out what kind of handles
were produced and still exist.

Can I do this kind of thing in the IDE? Do I need a tool? FYI, I'm using
..net 2003 v7.1 and fw 1.1, sp1.


After some trial and error, I find that the leak is associated with starting
threads. The threads are background threads not in the threadpool. The
threads are started with Threading.Thread.Start, and they run to completion.
As time passes, Task Manager reports steadily rising Handles. If I replace
the .Start call with a direct call to the same method (ie continue
functioning as before but entirely on one thread), then the handle leak goes
away. On a keystroke, the app will garbage collect, so I can see what task
manager is reporting with or without coerced garbage collection.

In summary, if MyThread will call sub Abcde() when started, then
MyThread.start leaks handles. If I replace MyThread.start with a direct call
to Abcde(), then there is no leak of handles.

I searched the internet, and I found others complaining about the same
problem. I found no solutions. What is going on?

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question