// 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; using System.Threading; class MainClass { private const int N = 10000000; public static void Main(string[] args) { Random rng = new Random(); for(int i = 0; i < 5; i++) { int[] a = new int[N]; for(int j = 0; j < a.Length; j++) a[j] = j; Console.WriteLine(a[rng.Next(N)]); GC.Collect(); Console.WriteLine(GC.GetTotalMemory(false)); Thread.Sleep(5000); int[] b = new int[N]; for(int j = 0; j < b.Length; j++) b[j] = j; Console.WriteLine(b[rng.Next(N)]); GC.Collect(); Console.WriteLine(GC.GetTotalMemory(false)); Thread.Sleep(5000); int[] c = new int[N]; for(int j = 0; j < c.Length; j++) c[j] = j; Console.WriteLine(c[rng.Next(N)]); GC.Collect(); Console.WriteLine(GC.GetTotalMemory(false)); Thread.Sleep(5000); a = null; b = null; c = null; GC.Collect(); Console.WriteLine(GC.GetTotalMemory(false)); Thread.Sleep(5000); } } }