[fpc-devel] Suggestion: reference counted objects

Sven Barth pascaldragon at googlemail.com
Thu Sep 25 19:36:15 CEST 2014


On 25.09.2014 17:23, Chriss Kalogeropoulos wrote:
> Hi Sven,
>
> Can you comment on how are you going to handle the case of
> TInterfacedObject and descendants? Are you going to use the same Addref
> & Release method ? How can you guarantee that the same counter will be
> updated in case of IUnknown implementations that introduce their own
> refcount variable (possibly with different name)?

There are two cases considering my RFC:
- an user uses TARCObject, then maybe we can provide a 
TARCInterfacedObject as well, which just implements AddRef and Release 
of IUnknown accordingly
- an user adds the refcounted modifier to an existing class type of 
which one of the parents used a reference counted interface as well; the 
best here would be to reimplement AddRef and Release to use the 
reference counting methods provided by the ARC class.

> Are you going to check that the class is already destroyed (because the
> arc has killed the instance) on IInterface.Release so that we should not
> get access violations on scenarios that mix ref counted classes and
> interfaces ?

This is not possible as in that case the reference would already be 
gone. But if you implemented the IUnknown reference counting using the 
ARC one then there shouldn't be any stray Release calls anyway, except a 
C++ (or another language that has no automatic reference counting for 
IUnknown) library has a bug regarding reference counting.

Regards,
Sven



More information about the fpc-devel mailing list