Am 06.04.2017 11:58 schrieb "Ryan Joseph" <r...@thealchemistguild.com>:
>
>
> > On Apr 6, 2017, at 4:26 PM, Sven Barth via fpc-pascal <
fpc-pascal@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
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to