Should struct destructors be required to be @nogc?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Sat Sep 16 00:47:52 UTC 2023


On Friday, September 15, 2023 5:32:00 PM MDT deadalnix via Digitalmars-d 
wrote:
> On Thursday, 14 September 2023 at 09:29:21 UTC, Commander Zot
>
> wrote:
> > 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.
>
> I don't see why that should be a problem at all. Java, C# and
> friend all support allocation during finalization and even object
> resurrection.
>
> At some point, we got to stop chasing the new trendy feature, and
> make sure the one we have work properly up to the standard a
> modern dev can expect.

I don't know enough about what D's GC is doing to know why it can't handle
this (or if I knew, I forgot), but certainly, I would agree that ideally,
the GC would just be able to handle having stuff allocated while a
destructor is running. And unless there's something fundamental preventing
it in D's case, it would definitely be a better solution than disallowing
allocating in destructors, much as needing to allocate in destructorss
should be pretty rare.

- Jonathan M Davis





More information about the Digitalmars-d mailing list