Am 07.05.2021 um 17:57 schrieb Ryan Joseph via fpc-devel:

On May 7, 2021, at 2:46 AM, Sven Barth via fpc-devel 
<> wrote:

I cannot speak for others, but I think 90% of potential use cases for ref 
would be covered like this in my code: objects that only live inside a

I think the same.
There's also a function which returns dynamically allocated memory but doesn't intend for you to 
keep it around very long. Cocoa/Objective-C has a good system for this which is an 
"autorelease pool" and while it's not language construct but rather a runtime system it 
does rely on an "Any" type (called id in Objective-C) so that methods can be chained 
together  like this:

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.

fpc-devel maillist  -

Reply via email to