// 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 Foobar : MarshalByRefObject { private byte[] b; public Foobar() { b = new byte[50000000]; } public byte[] B { get { return b; } } } 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("Create app domain with 50 MB object"); AppDomain d = AppDomain.CreateDomain("arne"); object o = d.CreateInstanceAndUnwrap("EE11", "E.Foobar"); PrintMemoryStatus(); Console.WriteLine("Unload app domain"); AppDomain.Unload(d); PrintMemoryStatus(); Console.WriteLine("Do GC"); GC.Collect(); PrintMemoryStatus(); } } }