DIP74 & GC Destructors
rsw0x via Digitalmars-d
digitalmars-d at puremagic.com
Mon Jun 15 05:14:26 PDT 2015
Andrei mentioned work on reference counting recently so I'm
assuming there's still plans on implementing DIP74¹.
With reference counted objects built into the language, it might
be worth investigating dropping destructors from all non-RC'd GC
allocated objects for a complete separation of objects that
control resources and need finalization, and objects that do not.
The current destructor implementation is incredibly bug prone,
and is often almost always misused. It has already been made
quite clear that you _can not_ rely on the GC for releasing
resources². The current GC is even non-reentrant³, meaning that
you can't allocate in destructors. You also have to assume any
other reference to heap-allocated memory is in an undefined state
during a destructor, further limiting their usefulness.
Furthermore, not having to worry at all about destructors would
improve the performance of the GC. The GC could just mark large
blocks of memory as free without having to scan which blocks of
memory have destructors, which can slow down sweeping(I have yet
to do any sort of testing on this, it is just a theory.)
One of the main concerns when choosing D as a language is the GC
performance, I think this is a well accepted fact. It's worth
evaluating anything that might improve the performance of the GC
in my opinion.
Bye.
¹ - http://wiki.dlang.org/DIP74
² - http://dlang.org/class.html#Destructor "... The garbage
collector is not guaranteed to run the destructor for all
unreferenced objects"
³ -
http://dlang.org/phobos/core_exception.html#.InvalidMemoryOperationError
More information about the Digitalmars-d
mailing list