Go, D, and the GC
Jonathan M Davis via Digitalmars-d
digitalmars-d at puremagic.com
Thu Oct 8 09:21:02 PDT 2015
On Thursday, 8 October 2015 at 15:58:37 UTC, Marco Leise wrote:
> Am Mon, 05 Oct 2015 13:42:50 +0000
> schrieb Adam D. Ruppe <destructionator at gmail.com>:
>
>> On Monday, 5 October 2015 at 07:40:35 UTC, deadalnix wrote:
>> > Not on the heap. There are many cases where the destructor
>> > won't run and it is allowed by spec. We should do better.
>>
>> To be fair, if you new a struct in C++ and never delete it,
>> the destructor will never run there either. D's in the same
>> boat in that regard.
>
> But the D boat reads "Garbage Collector". And besides, D now
> runs dtors on new'd structs. The "many cases" may be different
> ones than you imagine.
It's still the case though that if the GC does not collect a
struct on the GC heap, its destructor is not going to be run. And
there's no guarantee that _anything_ on the GC heap will ever be
collected. That depends on stuff like the memory usage of the
program. We're better off than we were, because when a struct on
the GC heap is collected, it's destructor will now be run,
whereas it wouldn't have been before, but ultimately, it's still
the same boat as C++ with regards to structs that never get
collected. It's just that in C++, you don't usually let memory
leak like that, whereas a GC doesn't normally collect everything
when the program shuts down. So, you're unlikely to run into a
case in C++ where a struct never gets destroyed, whereas it's
pretty easy in D.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list