[fpc-devel] Suggestion: reference counted objects

Sven Barth pascaldragon at googlemail.com
Sat Sep 27 22:06:56 CEST 2014


On 27.09.2014 18:45, Marco van de Voort wrote:
> In our previous episode, Sven Barth said:
>>
>>> It looks to me like inside methods Self doesn't deserve refcounting,
>>> because a method can be invoked only with an existing instance, which
>>> will stay alive at least until the call returns.
>>
>> That's the thing I'm not yet entirely sure about. Though disabling it
>> for Self would definitely simplyfy things. I'll simply give it a try and
>> then my constructor problems should hopefully be solved as well...
>
> Methods might return SELF as function result?

This would only be a potential problem if such methods are used inside 
the class itself. And even then it would only be a problem if there 
wouldn't still be another reference to the object and if there wouldn't 
be on then there would be no reason for the object to be around anyway.
The only case where this could really be a problem would be the 
constructor and there we simply would need to initialize the reference 
count with 1 and decrease it at the end of the constructor. Hint: 
TInterfacedObject does exactly that already.

Regards,
Sven




More information about the fpc-devel mailing list