// 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.Diagnostics; namespace E { public class MainClass { public static void PrintMemoryStatus() { Console.WriteLine("Application has allocated from .NET " + GC.GetTotalMemory(false)/1000000 + " MB"); Console.WriteLine(".NET has allocated from Windows " + Process.GetCurrentProcess().PrivateMemorySize/1000000 + " MB"); } public static void Main(string[] args) { Console.WriteLine("Startup"); PrintMemoryStatus(); Console.WriteLine("Allocate 50 MB"); byte[] b = new byte[50000000]; PrintMemoryStatus(); Console.WriteLine("50 MB ready for GC"); b = null; PrintMemoryStatus(); Console.WriteLine("Do GC"); GC.Collect(); PrintMemoryStatus(); } } }