C# Application Thread is running away

I think I have some run away threads...

I am creating threads, like so (for a custom MessageBox that I have made):

Thread newThread = new Thread(new ThreadStart(this.threadMethod));

Now my application's memory is constantly growing... and will not stop...

Is there a way to clean up Threads that are finished running?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

When the thread is finished you can set newThread=null; and see if that helps any.
try this one

newThread.Dispose(); //I think it should help
SPUH dispose is not a method for threads.  Unless I am missing something somewhere along the way.
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Yes, thats true, I was wrong. May be this one disposes the Thread: newThread.Abort();
Doe ThreadMethod() ever exit?
newThread.Abort() "Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread."  


This is not the graceful way to take care of this.

When a thread is finished executing it should eventually be collected by the Garbage Collector.  However, one never knows when the GC will be called.

Also, what are you doing within the code on the new thread?

Check this little tidbit out... requires less scanning than msdn.


Do you perchance use a timer that never gets disabled?
In c#, once a thread (or any object) is done, the clr's garbage collector gets rid of all memory used. That's why it is called managed code and managed memory.

A thread is considered done when the executed routine is finished. Could you log all entries and exits from your thread? My guess is you are possibly doing something in the thread that never ends or uses enough cpu cycles, that among all the threads, the clr never gets to clean up.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.