On 5/8/2021 8:27 PM, Ryan Joseph via fpc-devel wrote:
That was a bad example. It's for ANY class really.

o := TObject.Create.AutoRelease;

Then next event cycle the autorelease pool frees all the objects added to it. 
Very simple but effective however we can't do this in Pascal without a new 
permissive return type.

You do not need any special language feature for that, you can simply do something like

    ReleaseLater(TObject.Create)

and have ReleaseLater and ReleaseQueuedObjects procedures in a shared unit like

    procedure ReleaseLater(Obj: TObject);
    procedure ReleaseQueuedObjects;

and have ReleaseQueuedObjects called on app idle. LCL already has something like that with TApplication.ReleaseComponent but, as the name implies, it is only for TComponent instances. However nothing prevents you from making your own, it is just a few lines of code and certainly an app with flow complex enough to need such a construct wont be bothered by a few additional lines for this.

You could even use type helpers to make it look like a method :-P.

Kostas

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to