Framework: Understanding the Garbage Collector

This sample shows some how to control how the Garbage Collector operates. It demonstrates when the garbage collector calls any Finalize methods on created objects, as well as how to supress finalization. 

Featured Highlights:

This tutorial demonstrates how to use the Garbage Collector (GC). In particular, it discusses:

Using the GC.Collect() method to force the garbage collector to run.
Improving garbage collector performance on certain objects by using the GC.SuppressFinalize() method.
How to mark an object for garbage collection (setting it equal to Nothing).  

Requirements:

Microsoft Visual Studio.NET Professional or greater.
Windows XP or Windows 2000

Running the Sample:

To run the sample:

  1. Doubleclick the How-To Intro to the Garbage Collector.sln file. 
  2. Click the buttons on the form to test the functionality.
  3. Examine the code in the sample to understand how the code works.
  4. Close the running application, and note how any unfinalized objects are finalized as the form is closed.

See Also:

System.GC Class, GC.Collect Method, GC.SuppressFinalize Method, Programming For Garbage Collection