public static int Main() { Console.WriteLine("Beginning phase 1"); GCUtil.AllocWithGaps(); Console.WriteLine("phase 1 complete"); // losing all live references to the unpinned byte arrays // this will fragment the heap with ~50 byte holes GCUtil.FreeNonPins(); GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); Console.WriteLine("Beginning phase 2"); bList = new List <byte[]>(); for (int i = 0; i < 1024 * 1024; i++) { byte[] unpinned = new byte[50]; bList.Add(unpinned); } Console.WriteLine("phase 2 complete"); GC.KeepAlive(gchList); GC.KeepAlive(bList); return(100); }