demonstrates forced garbage collection 1
/* Mastering Visual C# .NET by Jason Price, Mike Gunderloy Publisher: Sybex; ISBN: 0782129110 */ /* Example21_14.cs demonstrates forced garbage collection */ using System; class Junk { public Junk() { Console.WriteLine("Created Junk"); } ~Junk() { Console.WriteLine("Destroyed Junk"); } } public class Example21_14 { public static void Main() { Console.WriteLine("Starting Main"); // create a Junk object Junk j = new Junk(); // and destroy it j = null; // force a garbage collection GC.Collect(); Console.WriteLine("Exiting Main"); } }