weak references : GC : Development C# Examples


C# Examples » Development » GC »

 

weak references









    
using  System;
using  System.Collections.Generic;
using  System.Globalization;
using  System.IO;
using  System.Text;
using  System.Security.Cryptography;

public  class  MainClass
{
        public  static  void  Main()
        {
                object  target  =  new  object();
                WeakReference  wr  =  new  WeakReference(target);
                Console.WriteLine("IsAlive:  {0}",  wr.IsAlive);
                GC.Collect();
                Console.WriteLine("IsAlive:  {0}",  wr.IsAlive);
        }
}
    
   
  
   



Output

IsAlive: True
IsAlive: False


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo Development
» GC