[fpc-pascal] Out of scope method?

Sven Barth pascaldragon at googlemail.com
Thu Apr 6 14:45:08 CEST 2017


Am 06.04.2017 11:58 schrieb "Ryan Joseph" <ryan at thealchemistguild.com>:
>
>
> > On Apr 6, 2017, at 4:26 PM, Sven Barth via fpc-pascal <
fpc-pascal at lists.freepascal.org> wrote:
> >
> > It's a difficult topic, cause in Object Pascal class instances are
always on the heap while in C++ they might be on the stack as well. Thus a
C++ compiler will insert calls to the destructor of such an object if it
goes out of scope.
> >
> > In Object Pascal currently only reference counted interfaces and (new
in trunk) records with management operators provide this feature.
>
> I see, but since there is a reference to an instance on the stack
wouldn’t it be trivial for the compiler to invoke a method on TObject
descendants when they go out of scope? If it does it for compiler types
like dynamic arrays I imagine it could do the same for classes.

Arrays are reference counted, class instances are not. So if the compiler
would blindly free the instance after it goes out of scope if might free
something that another code part still uses.

Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20170406/09dbb925/attachment.html>


More information about the fpc-pascal mailing list