GC.GetGeneration : GC « System « C# / C Sharp by API






GC.GetGeneration

  
using System;
using System.Collections.Generic;
using System.Text;

public class Car {
    private int currSp;
    private string petName;

    public Car() { }
    public Car(string name, int speed) {
        petName = name;
        currSp = speed;
    }

    public override string ToString() {
        return string.Format("{0} is going {1} MPH",
            petName, currSp);
    }
}
class Program {
    static void Main(string[] args) {
        Console.WriteLine("Estimated bytes on heap: {0}", GC.GetTotalMemory(false));
        Console.WriteLine("This OS has {0} object generations.\n", (GC.MaxGeneration + 1));

        Car refToMyCar = new Car("Zippy", 100);
        Console.WriteLine(refToMyCar.ToString());

        Console.WriteLine("\nGeneration of refToMyCar is: {0}", GC.GetGeneration(refToMyCar));
    }

    public static void MakeACar() {
        Car myCar = new Car();
    }
}

   
    
  








Related examples in the same category

1.GC.AddMemoryPressure
2.GC.GetTotalMemory
3.GC.MaxGeneration
4.GC.RemoveMemoryPressure