[fpc-devel] Suggestion: reference counted objects
Sven Barth
pascaldragon at googlemail.com
Sun Sep 28 21:22:19 CEST 2014
On 28.09.2014 21:00, Constantine Yannakopoulos wrote:
> Hi Sven,
>
> On Sat, Sep 27, 2014 at 7:33 PM, Sven Barth <pascaldragon at googlemail.com
> <mailto:pascaldragon at googlemail.com>> wrote:
>
> Huh? Delphi really prohibits such things inside the destructor?
> Would you mind to share an example (possibly including error
> messages), please?
Ah, ok. That was indeed not clear enough. ;)
>
> Sorry, I wasn't clear enough.
> With "prohibits" I didn't mean that you get a compiler error. It
> compiles and runs just fine but you get a stack overflow at runtime
> when the dest
> ructor is called
> .
>
> I've done a different approach already: the decrease helper sets
> refcount to -1 directly before it calls the destructor and both the
> increase and the decrease helper check for -1. Considering that it's
> currently only a proof of concept I can live with the performance
> impact that comparison might have.
>
>
> OK, but keep my proposal in mind since it has overhead only at
> BeforeDestruction which is once per instance lifecycle.
I can't use BeforeDestruction per se, because the user can override it.
But it would be possible to insert the code at the same location where
BeforeDestruction gets called... I'm doing something similar for
NewInstance currently where I force the reference count to 1.
Regards,
Sven
More information about the fpc-devel
mailing list