Destructors vs. Finalizers

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Wed Jul 26 05:43:27 PDT 2017


On 7/26/17 8:19 AM, Guillaume Piolat wrote:
> On Wednesday, 26 July 2017 at 02:58:00 UTC, Mike Parker wrote:
>> When cleaning up, the GC will ensure that all destructors are run 
>> where they exist, followed by all finalizers. And destroy would be 
>> changed to call rt_destruct instead of rt_finalize.
>>
>> Thoughts?
> 
> I don't get the distinction between destructors and "finalizers" but 
> imho the problem is very much that the GC is calling ~this.

In D, the difference is when the thing is called. If it's called 
deterministically, either by function or by the compiler, then you have 
a lot more flexibility. If it's by the GC, it can be out of order with 
regards to your members, it could be on a different thread than the one 
that owned it, etc.

Regarding the OP, I think we really should strive to have something to 
fix this issue.

A poor-mans distinction could be done by checking whether the GC is 
currently the one destroying (a flag is available, but isn't publicly 
accessible), though that could get expensive.

-Steve


More information about the Digitalmars-d mailing list