[fpc-devel] Defer keyword

Ryan Joseph genericptr at gmail.com
Sat May 8 19:27:26 CEST 2021



> On May 8, 2021, at 8:05 AM, Sven Barth <pascaldragon at googlemail.com> wrote:
> 
>> a := TArray.Create([1,2,3]).AutoRelease;
>> 
>> We can't do this in Pascal because the AutoRelease functions return type is not compatible with the type of the caller. Could we add something like an "Any" return type to Pascal which is a type that is compatible with any class? This relies on an event loop that can capture this garbage and dispose of it but it goes a LONG way in helping with common memory management problems.
> 
> Dynamic arrays are reference counted, thus you don't need to do any manual memory management on them.

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. 

Regards,
	Ryan Joseph



More information about the fpc-devel mailing list