Should struct destructors be required to be @nogc?

Commander Zot no at no.no
Thu Sep 14 09:29:21 UTC 2023


On Thursday, 14 September 2023 at 03:03:38 UTC, Jonathan M Davis 
wrote:
> On Wednesday, September 13, 2023 7:39:25 PM MDT bachmeier via 
> Digitalmars-d wrote:
>> [...]
>
> Well, if the class or struct is on the stack, being @nogc 
> should be unnecessary (the same if you're using an allocator 
> other than the GC allocator), because it won't be run when the 
> GC is running a collection. So, arguably, requiring @nogc would 
> be too restrictive for some use cases. However, it's also true 
> that they could just as easily be on the heap and run into a 
> similar issue (particularly with classes, since they almost 
> always live on the GC heap). So, an @nogc requirement would 
> likely make sense for most use cases, but I don't know how 
> reasonable it is to absolutely require it.
>
> - Jonathan M Davis

i'd prefer: don't call destructors from the GC at all, it was 
never guaranteed anyway as far as i know. introduce finalizers, 
which are _only_ called by the GC and are @nogc.


More information about the Digitalmars-d mailing list