Friday, June 7, 2013

Memory Management of Threads in .Net

We have seen that the .Net run-time manages the variables and objects in Stacks and Heaps based on their type. Value types are stored in the Stack and reference types are stored in the Heap. This is fine for a single threaded application, what happens when your application uses multiple threads?
We shall see on how memory is allocated and de-allocated for multi-threaded applications in this post.
As far as Heaps are concerned, Creation of additional threads has no impact, all the threads will use the same Heap to store their objects. 

In case of Stacks, each thread has its own stack. When a new thread is invoked a Stack is created and tagged to the thread, all variables, method calls, parameters etc. specific to that thread are stored in the Stack. However when a reference type is created in the new thread it is stored in the same Heap which is used by other threads and a reference is made from the Thread specific Stack to the general Heap where the objects are stored.

Search Flipkart Products:

No comments: