.NET application uses 2 types of Managed Heaps:
1: 2: 3: 4: 5: |
|
To minimize allocation time and almost eliminate heap fragmentation, .NET allocates objects consecutively, one on top of another, and keeps track of where to allocate the next object. (using NextObjPtr)
After Object A will be collected, it would leave a gap on the Heap. To overcome the fragmentation problem, the GC compacts the heap, and thereby removes any gaps between objects
Navigating through huge object graphs and copying lots of live objects over the top of dead ones is going to take a significant amount of processing time.
Perform garbage collection based on object's live-time.
The IDisposable interface defines the Dispose method used to release allocated (i.e. unmanaged) resources. When utilizing a class that implements this interface, it is clearly best to ensure that the Dispose method is called when the object is no longer needed.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: |
|
1: 2: 3: 4: 5: |
|
Unmanaged resources such as files/disks, network resources, UI elements or databases would not be closed (disposed) automatically unless you call Dispose method. If !! you write such classes to ensure that your resources will be freed up you have to provide finalizers.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: |
|
Even if Object Z would loose its root reference it would be promoted to Gen 2 and moved from the finalization queue to another queue, called the fReachable queue.
Periodically, the finalization thread will run, and it will iterate through all objects pointed to by references in the f Reachable queue, calling the Finalize method or destructor on each one and removing its reference from fReachable.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: |
|
LOH key features: