An idea for GC and freeing of resources without finalization
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Thu Jun 17 11:02:17 UTC 2021
On Thursday, 17 June 2021 at 10:50:41 UTC, rikki cattermole wrote:
> Alternatively we could make scope actually work for us.
>
> With scope as a storage class we can assume that there is an
> owning point on the stack for a give handle (the language nor
> druntime is aware of the handle itself).
>
> When that owning point goes out of scope, either the container
> gets destroyed or an operator overload gets called saying scope
> ends now!
>
> Along with another operator overload that allows you to return
> a seperete reference to that handle when you try to escape
> scope, done!
I am thinking that one does not exclude the other! :-D
So you would encourage people to free up resources explicitly, to
avoid frequent collection, but maybe you want to quickly tear
down a task, or maybe an exception was thrown in such a way that
a resource handle was lost (e.g. in a constructor). Then you can
still assume that the resource will be collected.
Either way, since all objects are traced anyway, and resource
handles are fairly rare, it won't cost much to tag them when
scanning pointers. I think the amortized cost would be close to
zero!?
The core focus is to speed up collection, making source code
cleaner and execution more robust. But yes, freeing resources
early should be the main strategy, but I think people will fail
to do this in more complicated patterns where resources are
involved in more async code that stuff resources handles into a
graph of some sort.
More information about the Digitalmars-d
mailing list