[fpc-devel] Suggestion: reference counted objects

Chriss Kalogeropoulos iz.iznogood at gmail.com
Thu Sep 25 20:13:50 CEST 2014

Hi again,

How would you handle the case of a user adding an interface on a class
marked as reference counted (like a tstringlist descendant, TArcStringList)
and then inherits from that and implements the IUnknown TFooStringlist
=class (TArcStringlist, IInterface).

Will he be able to hook on the addref and release methods of the arc object
? Or at the least use the refcount variable? Will it be done automatically
by the compiler (by using the same method names maybe) ?

 Στις 25 Σεπ 2014 6:36 μ.μ., ο χρήστης "Sven Barth" <
pascaldragon at googlemail.com> έγραψε:

> 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
> _______________________________________________
> 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/20140925/405c3756/attachment.html>

More information about the fpc-devel mailing list