Display current generations : GC : Development C# Examples


C# Examples » Development » GC »

 

Display current generations









    
using  System;

public  class  MyClass  :  IDisposable
{
    ~MyClass()
    {
        Console.WriteLine("In  destructor!");
    }
    
    public  void  Dispose()
    {
        Console.WriteLine("In  Dispose()  for  {0}!");
        GC.SuppressFinalize(this);
    }
}

public  class  MainClass
{
    public  static  void  Main(string[]  args)
    {        
        MyClass  c1,  c2,  c3,  c4;

        c1  =  new  MyClass();
        c2  =  new  MyClass();
        c3  =  new  MyClass();
        c4  =  new  MyClass();
        
        Console.WriteLine("\n*****  Displaying  generation  of  cars  *****");
        Console.WriteLine("C1  is  gen  {0}",  GC.GetGeneration(c1));
        Console.WriteLine("C2  is  gen  {0}",  GC.GetGeneration(c2));
        Console.WriteLine("C3  is  gen  {0}",  GC.GetGeneration(c3));
        Console.WriteLine("C4  is  gen  {0}",  GC.GetGeneration(c4));
    }
}
    
   
  
   



Output

***** Displaying generation of cars *****
C1 is gen 0
C2 is gen 0
C3 is gen 0
C4 is gen 0
In destructor!
In destructor!
In destructor!
In destructor!


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» GC