| Author: Gajalakshmi 02 Mar 2004 | Member Level: Bronze | Rating: Points: 2 |
The Memory management in the COM Based Architectures is Reference Counting. But In Case of .NET, It Differs entirely. It Is Reference Tracing.
Reference Counting: Whenever an Object gets created in the Heap, an Reference count gets increased and When it gets deleted, the reference count of the object is decreased. It is the Developers responsibility 'to ensure the proper release of the allocated resources.
Reference Tracing: In .NET, Automatic Memory management takes place by Reference Tracing and the Garbage Collector is responsible for handling this.
Lets first look at the object allocation in Heap:
Heap's storage is classified as follows: 1. Free space 2. Reserved Space
Whenever an Object gets allocated in the heap, the following Rules have to be followed.
1. Memory allocation takes place in a Continuous Range of the Free Space. 2. The order of objects in memory remains the order in which they were created, for good locality. 3. There are never any gaps between objects in the heap. 4. The Oldest Objects are in the lowest address.
GC Algorithm: The Reference Tracing does not occur once the object goes out of scope. The GC starts its work] when the memory in the heap is full.
The GC checks for each and every object if it is "reachable". To determine reach ability, the GC starts at all root objects - which are basically all static (shared in VB.NET) members and all in-scope local variables - and traverses the complete object reference graph. Each object which is encountered by the GC on its way is marked as alive.
Objects in the Heap will be in any of the two states: LIVE DEAD
In a second pass, all non-marked objects are destroyed, their resources freed, and finally the heap is compacted again to prevent memory fragmentation.
|
| Author: Rupreet Singh 02 Mar 2004 | Member Level: Bronze | Rating: Points: 2 |
Just to add, here is a link which will tell you in detail about the working of GC.
http://msdn.microsoft.com/msdnmag/issues/1100/gci/ http://msdn.microsoft.com/msdnmag/issues/1200/gci2/
Hope this helps
Regards, Rupreet Singh
|
| Author: asdf 08 Aug 2008 | Member Level: Silver | Rating: Points: 0 |
• Garbage collector To destroy “no longer referenced objects” by destructor(finalization) to make memory free. Whenever the memory full the destructor will be called by Garbage collector at regular interval to clean up the memory. But notable thing is Destructor take more resources like unwanted memory and Finalization Act in separate thread like again eating resources
|