[fpc-devel] Suggestion: reference counted objects

Chriss Kalogeropoulos iz.iznogood at gmail.com
Sat Sep 20 13:02:40 CEST 2014


Hi all,

Why would anyone want something like that? Both languages have interfaces
that can be used for auto reference counting and they also provide us with
a very powerful abstraction mechanism.
This also adds overhead on the performance (and locking calls) which might
be important in some cases like embedded devices.

The fact that embarcadero added this feature unconditionally is a huge
mistake IMHO unless they needed it for some compatibility reasons with java
for android or iOS or just marketing, I don't know. If someone knows any
other reason please post it on the list.

It's the same bad decision they made with the zero based strings, at least
the used a switch for that.

The only gain I can see from that is that with objects someone can use
reference counting and still benefit from some aggressive optimisation like
inlining which is not possible for interfaces. The same with simple
properties that they need getter and setter methods in interfaces that
cannot be optimized but in objects it might be possible or they can access
the data member directly.

In my opinion this is a very small gain compared to the huge change in the
language semantics that you propose.

Chriss
 Στις 20 Σεπ 2014 1:41 μ.μ., ο χρήστης "Hans-Peter Diettrich" <
DrDiettrich1 at aol.com> έγραψε:

> Fabrício Srdic schrieb:
>
>> Hello,
>>
>> In platforms with managed code (.NET, Java), objects are automatically
>> freed by the memory manager / garbage collector.
>>
>> Would not it be interesting to have a similar feature in FPC?
>>
>
> AFAIK some Delphi XE made TObject itself managed, by reference counting.
> It would be easy to introduce the same feature in FPC, so that no special
> base class would be required. Like with extended RTTI a decision should be
> made, whether managed objects should be enabled or disabled by default.
> Afterwards automatic management can be turned on or off for every single
> class or object individually.
>
>  For example, through a root class where its objects are counted by
>> reference, like the TInterfacedObjects. Thus, the programmer would be free
>> from having to manually release objects.
>>
>
> In practice it turned out that the automatic destruction of objects still
> requires assistance of the coder, in many cases, in all languages with
> garbage collection. I.e. a destructor (or finalizer) still is required to
> prepare an object for subsequent destruction.
>
> IMO it's sufficient to use Interfaces for all objects that should be
> subject to garbage collection.
>
> DoDi
>
> _______________________________________________
> fpc-devel maillist  -  fpc-devel at lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20140920/3fe77306/attachment.html>


More information about the fpc-devel mailing list