Destructors vs. Finalizers
Guillaume Piolat via Digitalmars-d
digitalmars-d at puremagic.com
Wed Jul 26 07:57:14 PDT 2017
On Wednesday, 26 July 2017 at 14:10:19 UTC, Moritz Maxeiner wrote:
> AFAICT that was mostly because it would have broken plenty of
> existing code.
The validity or purposefulness of such code is up to debate, a
separate debate granted.
Let's assume there is working code that such a change will break.
> Properly separating destruction and finalization from each
> other with the current syntax remaining as finalizers and the
> new one for destructors would allow this to be done without
> major code breakage.
Sure, in the event D would like to transition towards a state
where the GC doesn't call finalizers, it seems useful.
From a marketing point of view having two destructors and
keyword/syntax just for this would be hard to defend, and it
would also need to explain the whole story.
Personally I'd be for:
~this() { /* deterministic one */ }
void finalize() { /* the one called by GC */ }
But then no transition path.
I'll defend the view point that there is _nothing_ useful to do
in a finalizer except to check if the destructor has already been
called.
More information about the Digitalmars-d
mailing list