How Garbage Collection Works

Two types of resources must be managed with which you should be familiar. These are managed resources and unmanaged resources. Managed resources are those about which the CLR knows how to manage because they are defined within the type specifications of the CLR. Unmanaged resources are those that the CLR will not know how to manage. Examples of such resources are those that require a Handle, such as a file or Windows resource (bitmap, icon, mutex, and so on).

The GC follows a simple mechanism for freeing heap memory of objects that are no longer being used within the application. Consider Figure 9.1.

Figure 9.1. Objects in the heap.

This figure represents the heap containing some objects allocated from an application. ...

Get Delphi for .NET Developer’s Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.