Smart pointers

Handling an object's life cycle in Delphi can be a pain. Each object that was created in code must also be destroyed; otherwise, the program will be losing memory. An attempt to solve this was the introduction of Automatic Reference Counting (ARC), which treats objects the same as interfaces. This experiment, however, is losing tract. It was recently announced that the Linux compiler will stop using ARC and that both mobile compilers (Android and iOS) will also be moved back to normal object implementation in the future.

We can simplify object life cycle management by using smart pointers. As in ARC, a smart pointer is reference counted, so the code knows when it should be destroyed and does that for us.

Delphi doesn't support ...

Get Mastering Delphi Programming: A Complete Reference Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.