Friday, December 22, 2006

* Microsoft.net - Automatic Memory Management

This post tells all about Garbage Collection in Microsoft.net in points :

1. Memory management in .NET is automatic which means developer doesn't need to worry about allocation/de-allocation or when to free memory. All this is taken care by Common Language Runtime using a process call Garbage Collector (GC).

2. All memory requirements are served from a managed heap.

3. Whenever a new process starts, runtime reserves a contiguous memory space for that process which becomes managed heap for that process.

4. All the memory requirements for the process are served from this heap.

5. Whenever there is no more free memory in the heap, the Garbage Collector becomes active and starts scanning the objects in heap which are no more in use.

6. All the objects are by default created in Generation 0 and if on first GC they are not available for collection, they are promoted to Generation 1. Maximum any object can go upto Generation 2.

7. As the new objects are more probable candidates for collection than older objects, GC always first scans Generation 0 objects only.

8. If the object has Finalize() method, it is called before getting collected. Collection of such objects is managed using data structures called Finalization Queue & Freachable Queue.

9. To optimize memory usage, .NET provides weak references which can be used to free up large memory objects temporarily.

 

No comments:

Post a Comment