public void WithoutFinalizer() { for (int i = 0; i < ForCount; i++) { var @object = new ClassWithoutFinalizer { A = 1 }; } }
public void RunIDisposableExamples() { Action a1 = () => { Console.Write("[Finalizer.IDisposable.Dispose] "); for (int i = 0; i < 1; ++i) { var instance = new ClassWithFinalizer(); instance.Dispose(); instance = null; } GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(); }; a1(); Action a2 = () => { Console.Write("[Finalizer.IDisposable.NoDispose] "); for (int i = 0; i < 1; ++i) { var instance = new ClassWithFinalizer(); instance = null; } GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(); }; a2(); Action a3 = () => { Console.Write("[NoFinalizer.IDisposable.Dispose] "); for (int i = 0; i < 1; ++i) { var instance = new ClassWithoutFinalizer(); instance.Dispose(); instance = null; } GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(); }; a3(); Action a4 = () => { Console.Write("[NoFinalizer.IDisposable.NoDispose] "); for (int i = 0; i < 1; ++i) { var instance = new ClassWithoutFinalizer(); instance = null; } GC.Collect(); GC.WaitForPendingFinalizers(); Console.WriteLine(); }; a4(); }