How is the memory managed for a thread?

101 views Asked by At

I understand that .net threads are pretty heavy weight, consuming ~1MB of memory each (mostly for the stack). Now, if this was a user .net class I know that it is likely going to put most of the memory into LOH. However, since it is a core class, I am wondering what the behavior is.

The reason for this question is because I am memory profiling an (potentially long lived) application at the moment, and there seems to be a slow leak. I had noticed that VS is showing 33 threads (in various states, included stopped). I am wonder if the frugal usage of threads could be fragmenting the memory (along with a few LOH DTOs).

1

There are 1 answers

0
Jim Mischel On BEST ANSWER

The thread's stack is not stored on the LOH because the stack is not a CLR object. The thread's stack is allocated by the operating system when .NET asks for a new thread.

A CLR thread is a thin wrapper around an operating system thread.

If you really do have a memory leak, you can be sure that it's not in the thread objects themselves.