More radical ideas about gc and reference counting

Benjamin Thaut via Digitalmars-d digitalmars-d at puremagic.com
Sun May 11 00:52:40 PDT 2014


Am 06.05.2014 05:40, schrieb Manu via Digitalmars-d:
>
> Does ~this() actually work, or just usually work?
> Do you call your destructors manually like C#?

Back when I actually used D's GC, it did usually work. There were a few 
workarounds because destructors would be called in the wrong thread, but 
other than that it did work for me.

By now I call my destructors manually like in C++. I do full manual 
memory management (I have a modified version of druntime that does not 
even contain the GC anymore). I always liked D because of its 
metaprogramming capabilities and not because of the automatic memory 
management. So I use D as a C++ with better meta programming. But this 
also means that I do not use phobos. I actually tried using only parts 
of phobos, but the dependency hell in phobos results in all modules 
being pulled in as soon as you use one central one, so I stopped using 
most of phobos alltogether. The annoying part, as you already pointed 
out, is that I can't use any third party libraries. So I'm living in my 
own little D world.

So I would be disappointed if classes suddently don't have destructors 
anymore. Most annoying would be the lack of compiler generated field 
destructors (e.g. automatically calling the destructor of each struct in 
the class). I could work around that, but it would be another anoyance 
over C++ and as they are piling up it becomes more and more viable to 
just go back to C++.
>
> I support the notion that if the GC isn't removed as a foundational
> feature of D, then destructors should probably be removed from D.
> That said, I really want my destructors, and would be very upset to
> see them go. So... ARC?
>

I think ARC could work, but should be extended with some sort of 
ownership notation. Often a block of memory (e.g. an array of data) is 
exclusivly owned by a single object. So it would be absolutly 
uneccessary to reference count that block of memory. Instead I would 
want something like Rust has, borrowed pointers. (We actually already 
have that, "scope" but its not defined nor implemented for anything but 
delegates)

Kind Regards
Benjamin Thaut



More information about the Digitalmars-d mailing list