Finalization

The freeing up of resources used by objects in the .NET world is different from what Delphi developers are used to. We already know that the GC will free managed resources from the heap when they are not used. It is still necessary to free unmanaged resources such as a file handle explicitly because the GC will not know how to do this.

In the past, freeing resources using Delphi relied on the destructor, which was called whenever the Free() method was invoked on the object. The destructor looked something like this:

destructor TMyObject.Destroy;
begin
  FreeResource;
  inherited;
end;

You still have the constructor in Delphi for .NET, but it does something different now. Before getting into how this is different, let’s look at the .NET ...

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.