On Friday, 26 May 2017 at 17:32:38 UTC, Igor Shirkalin wrote:
On Friday, 26 May 2017 at 17:17:39 UTC, Stanislav Blinov wrote:
Destructors of derived classes are called implicitly on finalization. The net effect is that such finalization adopts the weakest set of attributes among all the destructors it calls.
I'm sorry, I ment explicitly. I hope it is not possible.

It is very possible, and it should be possible, otherwise we couldn't even think about deterministic destruction.

Another side, clearly demonstrated by my second post, is that non-deterministic destruction cannot be @safe, period. Because when GC collects and calls destructors, it calls all of them, regardless of their @safe status, even when the collection is triggered inside a @safe function.

Doesn't that mean if compiler can't call inherited destructor despite of GC it must be error?

1) Destructors are not "inherited" in D. Each derived class has it's own independent destructor. That's why they don't inherit any attributes either.

2) Compiler doesn't call destructors for classes. It is done either manually (by calling destroy()) or by the GC. Look at the example in the second post: I'm in @safe function (important()), I need some memory. I ask for it, the GC decides to do a collection before giving me memory. And during that collection it calls a @system destructor. So the language and runtime are effectively in disagreement: language says "no @system calls in @safe context", runtime says "whatever, I need to call those destructors".

Reply via email to