November 2019
Beginner to intermediate
674 pages
15h
English
From the viewpoint of memory management, interfaces in Delphi are implemented as classes with added reference counting. To create an interface, you actually have to create an object of a class, which will get a reference count of 1. If you then assign this interface to another variable, both will point to the same memory and the reference count will be incremented to 2.
There is no equivalent to SetLength or UniqueString that would make a unique copy of an interface. That would require duplicating the underlying object and Delphi has no built-in support for that.
The object implementing the interface is destroyed when its reference count falls to 0:
var i1, i2: IInterface;begin i1 := TInterfacedObject.Create; // i1 points to an ...
Read now
Unlock full access