423,688 Members | 1,879 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,688 IT Pros & Developers. It's quick & easy.

handle leak

P: n/a
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.

Jul 5 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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?
"AMercer" wrote:
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.
Jul 5 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.