[fpc-pascal] Managed properties idea

Michalis Kamburelis michalis.kambi at gmail.com
Sat Oct 7 02:10:47 CEST 2017


2017-10-06 23:55 GMT+02:00 Maciej Izak <hnb.code at gmail.com>:
> ... and here is library with exclusive usage of "management operators" for
> FPC:
>
> https://github.com/pda0/AutoScope
>
> ... and here is experimental smart pointers/objects/nullable types
> implementation:
>
> https://github.com/maciej-izak/PascalSmartPointers
>

Oooh this is perfect, thank you for this. And I do mean both projects.

I see that AutoScope (
https://github.com/pda0/AutoScope/blob/master/AutoScope.pas ) is using
management operators in new FPC, or internal COM interface (FGuardian)
in older FPC or Delphi. Although AutoScope only "frees when outside of
scope", it doesn't try to implement a full equivalent of a shared
pointer. So if you store the instance of your object (like
TSomeObject1 mentioned in https://github.com/pda0/AutoScope example)
in some global variable / field, then you can end up with having an
invalid reference (pointing to already-freed object). Unless you also
store the relevant TScope instance in the same scope.

Your TSmartObj is, well, exactly what I want:) As long as you pass
around only "TSmartObj<TSomeObject1>" (and don't create cycles :) ),
you're perfectly safe and leak-free.

Regards,
Michalis



More information about the fpc-pascal mailing list