troubleshooting Question

Multi threaded windows service - memeory leak

Avatar of cp30
cp30Flag for United Kingdom of Great Britain and Northern Ireland asked on
.NET ProgrammingVisual Basic.NET
16 Comments2 Solutions320 ViewsLast Modified:

I have a vb .net multi-threaded windows service.  There are 3 main functions that carry out various work and database reading/writing and these "worker" functions loop indefinitely.

When the service starts it creates a predefined number of each thread i.e. 5 threads are created and run Function1, 5 created and run Function2 and 5 for Function3.  So, I have 15 threads altogether, each doing their job, looping and starting again to process outstanding work from the database.

In each function, I have a label at the start i.e.
and at the  end of the function we have
Goto StartOfFunction
.  I have error handling with try catch block which seems to work pretty well as I don't get any situations where exceptions means that the thread exits the function.

The service runs ok for about 24 hours but slowly builds in memory used and requires a restart which, obviously, is not ideal. So it seems that there is a small memory leak somewhere along the way.

I'm not sure what I need to be explicitly doing in order to prevent this, is there certain data types I need to manually dispose or set =nothing? Should I call something before the loop back to the start?  

I'm using a variety of different objects, I can provide exact details if neccessary, but summary is... string, integer, dataset, datatable, XmlTextReader, WebClient, etc. etc.

The functions can also make calls to other functions to perform database operations or xml transformations etc.

Let me know if you need any more info, but any advice would be greatly appreciated.

Many thanks
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 16 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 16 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros