[fpc-devel] weak referencing (was Suggestion:.....)
pascaldragon at googlemail.com
Mon Sep 22 19:21:46 CEST 2014
Am 22.09.2014 17:11 schrieb "Jonas Maebe" <jonas.maebe at elis.ugent.be>:
> On 22 Sep 2014, at 16:44, Peter Popov wrote:
>> Another comment: If referenced objects all derive from a single base,
then, the user cannot possibly have another hierarchy, which uses ref.
objects. As I mentioned earlier, I do this explicitly for an object well
down my hierarchy. So, it seems to me you still need something like:
>> -- code --
>> TRefObject = referenced class(TWhateverBase)
> I would strongly recommend against that. Referenced and unreferenced
objects are completely different beasts with different behaviours. If you
allow that, you get all kinds of problems down the line. E.g. you either
have to forbid assigning a TRefObject to a TWhateverBase (which runs
counter to a very basic OOP principle), or allow it and then have the
programmer deal with the resulting reference counting mess-ups.
As written in my RFC I would go the "allow it" route and provide mechanisms
to manually access the reference count from a non-reference counted
variable (thus being implemented in TObject). Optionally one could add a
warning that is off by default that one could use for such cases. This
approach is necessary, because we'd otherwise need to introduce overloads
for e.g. RTTI functionality in TypInfo or to introduce some compiler magic
for them (I don't like either of these two possibilities).
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the fpc-devel