My guess here is if you use Thread like this
new Thread(unused => HandleClientCommunication(clientConnection)).Start();
}
and if you have let's suppose 100 calls per second you will end up with 100 MB more at least in your App as each thread will require 1MB at least remember that garbage collector can not guarantee that memory will always be collected even if thread has finish the execution.
what I can suggest here is to switch all your code to use Task.
your code will look something like this
Task.Factory.StartNew(unused => HandleClientCommunication(clientConnection));
}
Here why you should use task over Thread (when it's possible)
- Creating and destroying a thread is an expensive operation in terms
of time
- Having lots of threads wastes memory resources and also hurts performance due
to the operating system having to schedule and context switch between the runnable threads
- Tasks are scheduled on a pool of threads. The specific number of threads depends on the scheduler used.If your application makes many requests of the thread pool, the thread pool will try to service all of
the requests using just this one thread. However, if your application is queuing up several requests
faster than the thread pool thread can handle them, additional threads will be created.