NET - Explain how the .NET Framework performs automatic memory management

Explain how the .NET Framework performs automatic memory management.

Automatic memory management involves two major steps:

1. Allocation of memory
2. Release of memory

Allocation of memory - When a new process is initialized, runtime reserves address space in memory for the process. This address space inside the memory is known as heap. At the very initial stage, the pointer is at the base address of managed heap. When the application creates an object, the garbage collector allocates memory in the address space immediately following the first object. As long as address space is available, the GC keeps allocating space to the objects one over another. Runtime allocates memory to an object by adding a value to a pointer pointing to previously allocated object. This makes it faster.

Releasing memory - Garbage collector figures out the best time to perform collection. This is done on the basis of how memory was allocated. GC releases all the unused objects. To find which ones are not in use, GC examines the application’s roots. All the application roots are assigned to the objects or are set to null. A graph is formed on the basis of this and the objects which are not part of this graph are released from the memory.
NET - What is Finalizer? Explain how to implement it
What is Finalizer? - It is a method that is executed when an object is garbage collected.......
VB.NET - Difference and similarity between a class and a structure
Difference and similarity between a class and a structure - Both the class and structure are user define types. Both are the template of the object...
VB.NET - What is implicit cast and explicit cast in .Net?
Implicit cast and explicit cast in .Net - Implicit cast allows conversion without any loss of data and it takes place only when there is no possible of loss of data. ....
Post your comment