| Author: ravindrababu.k 16 Aug 2006 | Member Level: Gold | Rating: Points: 2 |
http://www.codeproject.com/dotnet/garbagecollection.asp
|
| Author: Dotnetjunkie 16 Aug 2006 | Member Level: Gold | Rating: Points: 2 |
Hello GC is invoked automatically and we can also force to run at any time by calling the function Collect(); GC has the 2 phases starting from 0,1 in first phase 0, it will Marked the unused memory in 1st phase, Move all the live objects to the bottom of the heap, leaving free space at the top.
and for more help For Automatic free memory management :::: http://msdn.microsoft.com/msdnmag/issues/1100/gci/
|
| Author: Vikram Singh Kshatriya 16 Aug 2006 | Member Level: Gold | Rating: Points: 2 |
The GC Class controls the system garbage collector, a service that automatically reclaims unused memory. Garbage collection in the Microsoft .NET common language runtime environment completely absolves the developer from tracking memory usage and knowing when to free memory. However, you'll want to understand how it works. When the garbage collector starts running, it makes the assumption that all objects in the heap are garbage. In other words, it assumes that none of the application's roots refer to any objects in the heap. Now, the garbage collector starts walking the roots and building a graph of all objects reachable from the roots. Once all the roots have been checked, the garbage collector's graph contains the set of all objects that are somehow reachable from the application's roots; any objects that are not in the graph are not accessible by the application, and are therefore considered garbage. The garbage collector now walks through the heap linearly, looking for contiguous blocks of garbage objects (now considered free space). The garbage collector then shifts the non-garbage objects down in memory (using the standard memcpy function that you've known for years), removing all of the gaps in the heap. Of course, moving the objects in memory invalidates all pointers to the objects. So the garbage collector must modify the application's roots so that the pointers point to the objects' new locations. In addition, if any object contains a pointer to another object, the garbage collector is responsible for correcting these pointers as well.
|