> On May 8, 2021, at 8:05 AM, Sven Barth <[email protected]> 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
_______________________________________________
fpc-devel maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel