In Delphi, you have several ways of handling data life time, therefore several ways of handling memory:
- For simple value objects (e.g.
byte integer double shortstringand fixed size arrays orrecordcontaining only such types), the value is copied in fixed-size buffers; - For more complex value objets (e.g.
stringand dynamic arrays orrecordcontaining such types), there is a reference counter handled by each instance, with copy-on-write feature and compiler-generated reference counting at code scope level (with hiddentry..finallyblocks); - For most
classinstances (e.g. deriving fromTObject), you have toCreatethenFreeeach instance, and manage its life time by hand - with explicittry..finallyblocks; - For
classderiving fromTInterfacedObject, you have aRefCountproperty, with_AddRef _Releasemethods (this is the reference-counted COM model), and you can use Delphiinterfaceto work with such instances - see this blog article.
class level are about to be introduced at the compiler and RTL
level.Even if this feature is not finished, and disabled, there are a lot of changes in the Delphi XE3 Run Time Library which sounds like a preparation of such a new feature.


