Blog: GC
Dukc
ajieskola at gmail.com
Sat Mar 6 23:57:25 UTC 2021
On Saturday, 6 March 2021 at 20:21:41 UTC, Rumbu wrote:
>
> I took the article with a grain of salt when I saw the author
> claiming that finalisation of classes is a problem in all
> garbage collected languages. It seems that the author failed to
> update himself or - what's worse - wants to justify D failure
> in having deterministic class destruction by pointing to others.
>
> C# has IDisposable/using and Java has AutoCloseable as
> mechanisms for deterministic destruction.
Those C#/Java mechanisms are for deterministic destruction, akin
to https://dlang.org/phobos/std_typecons.html#scoped. Mike warned
only about indeterministic destructors -those that are only
invoked when/if the object gets collected.
To be precise, class destructors are not any more problematic
than struct desturctors if they are always called
deterministically -see
https://dlang.org/phobos/object.html#.destroy. But if the
destructor needs to be called manually anyway, why should it be a
destructor at all? It's probably better to put the finalizing in
a normal function, or better yet to a destructor of a RAII struct.
Problems with GC-called destructors are not unique to D -see
https://theartofmachinery.com/2018/12/05/gc_not_enough.html for a
Ruby example.
> I remember when D had built-in allocator support and delete for
> deterministic destructors. Now they are deprecated and we have
> a library solution :)
I don't see why library solutions would be inherently inferior.
What do we lose in case of deterministic destruction?
More information about the Digitalmars-d
mailing list