Best article on Gabage Collection i have ever seen on the earth !!
Apart from Garbage collection it also tell u about Weak References...
Weak references are a means of performance enhancement, used to reduce the pressure placed on the managed heap by large objects.
When a root points to an abject it's called a strong reference to the object and the object cannot be collected because the application's code can reach the object.
When an object has a weak reference to it, it basically means that if there is a memory requirement & the garbage collector runs, the object can be collected and when the application later attempts to access the object, the access will fail. On the other hand, to access a weakly referenced object, the application must obtain a strong reference to the object. If the application obtains this strong reference before the garbage collector collects the object, then the GC cannot collect the object because a strong reference to the object exists.
http://www.codeproject.com/dotnet/garbagecollection.asp
To support this article, we have another article by our Windows Guru Jeffery Richter
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/default.aspx
Sample Code for Weak References:
Void Method() {
Object o = new Object(); // Creates a strong reference to the
// object.
// Create a strong reference to a short WeakReference object.
// The WeakReference object tracks the Object.
WeakReference wr = new WeakReference(o);
o = null; // Remove the strong reference to the object
o = wr.Target;
if (o == null) {
// A GC occurred and Object was reclaimed.
} else {
// a GC did not occur and we can successfully access the Object
// using o
}
Bye for Now..Will come again !!
Monday, April 25, 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment