[fpc-devel] Suggestion: reference counted objects
Sven Barth
pascaldragon at googlemail.com
Sat Sep 27 16:14:21 CEST 2014
On 27.09.2014 16:06, Hans-Peter Diettrich wrote:
> Sven Barth schrieb:
>
>> There are however some nasty problems inside constructors and
>> destructors, because "Self" is reference counted as well (and should
>> be after all as we don't want the instance to be destroyed behind our
>> backs suddenly).
>
> IMO before the end of a constructor, and before the start of an
> destructor, no references to the object exist at all, so that code
> outside these methods has no reference that could cause trouble.
The problem is that a destructor can call other methods which might take
the object reference as a parameter and each such passing will have
calls to the reference counting again. So there needs to be a way to
avoid infinite calling of the destructor. (I fixed this for now by
simply disabling reference counting with a -1 reference count when the
destructor is called by the reference count decrease helper).
> 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...
Regards,
Sven
More information about the fpc-devel
mailing list