The garbage collector checks to see whether there are any objects in the heap that are no longer being used by the application. If such objects exist, the memory used by these objects can be reclaimed. (If no more memory is available in the heap, then
new throws an
OutOfMemoryException exception.) How does the garbage collector know whether or not the application is using an object? As you might imagine, this isn’t a simple question to answer.
Every application has a set of roots. A single root is a storage location containing a memory pointer to a reference type. This pointer either refers to an object in the managed heap or is set to
null. For example, all global or static reference type variables are considered ...