1 using System; 2 using Mono.ObjectServices; 3 4 class Demo { 5 6 int a; 7 Main()8 static void Main () 9 { 10 Demo d = new Demo (); 11 12 prints ("d", d); 13 prints ("dd", new DD ()); 14 prints ("short str", "short"); 15 prints ("long str", "this is a longer string which we want to measure the size of"); 16 17 object[] obj_array = new object [100]; 18 19 prints ("obj array", obj_array); 20 21 for (int i = 0; i < 100; i++) 22 obj_array [i] = new Demo (); 23 24 prints ("obj array w/ demos", obj_array); 25 } 26 prints(string s, object x)27 static void prints (string s, object x) 28 { 29 Console.WriteLine ("size of " + s + ":" + ObjectInspector.GetMemoryUsage (x)); 30 } 31 } 32 33 class DD { 34 Demo d = new Demo (); 35 object [] o = new object [10]; 36 char [] ch = new char [10]; 37 int junk; 38 DD()39 public DD () 40 { 41 o [0] = new Demo (); 42 o [5] = new Demo (); 43 } 44 } 45