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
. 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.