Figures
Figure 1 Strong and 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
   }
}
Figure 5 GC Methods Demonstration
private static void GenerationDemo() {
    // Let's see how many generations the GCH supports (we know it's 2)
    Display("Maximum GC generations: " + GC.MaxGeneration);

    // Create a new BaseObj in the heap
    GenObj obj = new GenObj("Generation");

    // Since this object is newly created, it should be in generation 0
    obj.DisplayGeneration();    // Displays 0

    // Performing a garbage collection promotes the object's generation
    Collect();
    obj.DisplayGeneration();    // Displays 1

    Collect();
    obj.DisplayGeneration();    // Displays 2

    Collect();
    obj.DisplayGeneration();    // Displays 2   (max generation)

    obj = null;         // Destroy the strong reference to this object

    Collect(0);         // Collect objects in generation 0
    WaitForPendingFinalizers();    // We should see nothing

    Collect(1);         // Collect objects in generation 1
    WaitForPendingFinalizers();    // We should see nothing

    Collect(2);         // Same as Collect()
    WaitForPendingFinalizers();    // Now, we should see the Finalize 
                                   // method run

    Display(-1, "Demo stop: Understanding Generations.", 0);
}
Figure 7 Counters to Monitor
Counter
Description
# Bytes in all Heaps
Total bytes in heaps for generations 0, 1, and 2 and from the large object heap. This indicates how much memory the garbage collector is using to store allocated objects.
# GC Handles
Total number of current GC handles.
# Gen 0 Collections
Number of collections of generation 0 (youngest) objects.
# Gen 1 Collections
Number of collections of generation 1 objects.
# Gen 2 Collections
Number of collections of generation 2 (oldest) objects.
# Induced GC
Total number of times the GC was run because of an explicit call (such as from the Classlibs) instead of during an allocation.
# Pinned Objects
Not yet implemented.
# of Sink Blocks in use
Synchronization primitives use sink blocks. Sink block data belongs to an object and is allocated on demand.
# Total committed Bytes
Total committed bytes from all heaps.
% Time in GC
Total time since the last sample spent performing garbage collection, divided by total time since the last sample.
Allocated Bytes/sec
Rate of bytes per second allocated by the garbage collector. This is only updated at a garbage collection, not at each allocation. Since it is a rate, time between GCs will be 0.
Finalization Survivors
Number of garbage-collected classes that survive because their finalizer creates a reference to them.
Gen 0 heap size
Size of generation 0 (youngest) heap in bytes.
Gen 0 Promoted Bytes/Sec
Bytes per second that are promoted from generation 0 (youngest) to generation 1. Memory is promoted when it survives a garbage collection.
Gen 1 heap size
Size of generation 1 heap in bytes.
Gen 1 Promoted Bytes/Sec
Bytes per second that are promoted from generation 1 to generation 2 (oldest). Memory is promoted when it survives a garbage collection. Nothing is promoted from generation 2, since it is the oldest.
Gen 2 heap size
Size of generation 2 (oldest) heap in bytes.
Large Object Heap size
Size of the Large Object heap in bytes.
Promoted Memory from Gen 0
Bytes of memory that survive garbage collection and are promoted from generation 0 to generation 1.
Promoted Memory from Gen 1
Bytes of memory that survive garbage collection and are promoted from generation 1 to generation 2.
Page view tracker