It is not clear whether you are asking:
- Why didn't Borland do this when they originally developed Delphi?
- Why doesn't Embarcadero do this in a future version of Delphi?
- Why don't I do this with my own custom data types?
Does this not mean that now everyone has calculated the link?
Yes, that would be.
However, you donβt necessarily want everything to be counted: every small integer, every line, every logical element, every element in the array ... if not for some other reason that the ref-counting implementation adds some overhead costs, such as a small additional memory per object, may be insignificant for large objects, but proportionally more significant if applied to each tiny object.
Also see also the Garbage Collector for objects and components of Delphi , which says (quote),
Delphi provides three ways to manage objects:
- Create / destroy objects using try..finally.
- Use TComponent descendants - create a component and allow its owner to free it.
- Interfaces - when the reference counter for an interface becomes 0, the object that implements it is destroyed.
Delphi help says you shouldn't mix TComponent owner approach with memory management interface, but ...
Will it be garbage collection?
Not really; simple reference counting is not as robust as garbage collection:
With reference counting, if you have two instances with reference counting, each of which contains a link to the other, then they are not automatically released. To free them, you need to break this "circular link" (i.e. Explicitly point one of them to release the link to the other).
With true garbage collection, the garbage collector would notice that these two values ββare not mentioned anywhere and free them both.
Update
If you comment on your potentially circular links as [weak] links, they will be destroyed in order. But before Delphi 10.1 Berlin, this only works on NexGen compilers (i.e. those who use LLVM under the hood). Starting with 10.1 in Berlin, these links [weak] work everywhere.
Chrisw
source share