// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Big { private static int total = 0; private int n; private byte[] a; public Big() { total++; n = total; a = new byte[50000000]; Console.WriteLine("Number " + n + " is new'ed"); } ~Big() { Console.WriteLine("Number " + n + " is ready for GC"); } } class TestClass { public static void Main(string[] args) { for(int i = 0; i < 100; i++) { Console.WriteLine("Call new"); Big o = new Big(); Console.WriteLine("Used memory: " + GC.GetTotalMemory(false)/1000000); Console.WriteLine("Set to null"); o = null; Console.WriteLine("Used memory: " + GC.GetTotalMemory(false)/1000000); } } } }