using System;
public class MyClass {
private string name;
public MyClass(string name) { this.name = name; }
override public string ToString() { return name; }
~MyClass() { Console.WriteLine("~MyClass()"); }
public void Dispose() {
Console.WriteLine("Dispose()");
}
}
public class GarbageDisposalApp {
public static void Main(string[] args) {
DoSomething();
Console.WriteLine("end of Main");
}
public static void DoSomething() {
MyClass t = new MyClass("Foo");
Console.WriteLine(t);
t.Dispose();
t = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
|