Why does D rely on a GC?

ponce via Digitalmars-d digitalmars-d at puremagic.com
Tue Aug 19 00:14:17 PDT 2014


On Monday, 18 August 2014 at 18:56:42 UTC, b wrote:
>
>  Besides that, in C++ it works like this.
>  90% of objects: value types, on stack or embedded into other 
> objects
>  9% of objects: unique types, use unique_ptr, no overhead
>  ~1% of objects: shared, use shared_ptr/weak_ptr etc.
>
>  With GC you give up deterministic behavior, which is 
> *absolutely* not worth giving up for 1% of objects.
>
>  I think most people simply haven't worked in an environment 
> that supports unique/linear types. So everyone assumes that you 
> need a GC. Rust is showing that this is nonsense, as C++ has 
> already done for people using C++11.

I work in such an environment and I tend to agree with you. We 
use a combination of std::unique_ptr and raw pointers as weak 
ref. It works without hiccup even though people have to ensure 
manually that lifetimes of owners exceed lifetime of borrowers. A 
problem with scoped ownership is that it makes the pointer know 
about the lifetime, and that forces to give up type-safety a bit 
to write function taking any pointer type.

In D having deterministic resource release is harder because 
scoped ownership is less polished than in C++.


More information about the Digitalmars-d mailing list