Invalid memory operation during allocation with `new`

Adam D. Ruppe destructionator at gmail.com
Sun Jan 12 17:36:23 UTC 2020


On Sunday, 12 January 2020 at 15:21:05 UTC, Per Nordlöw wrote:
> - in the short run,
>   Qualifying all user-defined class destructors with `@nogc`?
>
> - in the long run,
>   Making DMD forbid GC-allocations transitively inside class 
> destructors?

The class doesn't necessarily know what its destructor is going 
to be used for, nor does as struct. So such static checks would 
end problematic; limiting to some legit cases and not catching 
some problem cases (because destructors are called with child 
classes to).

The most recent release added a runtime function you can test 
though:

https://dlang.org/phobos/core_memory.html#.GC.inFinalizer

so if that is true, avoid doing the call.

Of course that doesn't help the case when you don't know the rule 
and don't even think to call it.......


More information about the Digitalmars-d-learn mailing list