Enforced @nogc for dtors?

Brian Rogoff via Digitalmars-d digitalmars-d at puremagic.com
Mon May 5 09:25:47 PDT 2014


On Monday, 5 May 2014 at 14:17:04 UTC, Orvid King via 
Digitalmars-d wrote:
> Also, the @nogc for destructors is specific to the current GC, 
> and is a limitation that isn't really needed were destructors 
> implemented properly in the current GC.

How does one implement destructors (described below) properly in 
a garbage collector?

I'm a bit puzzled by the recent storm over destructors. I think 
of garbage collected entities (classes in Java) as possibly 
having "finalizers", and scoped things as possibly having 
"destructors". The two concepts are related but distinct. 
Destructors are supposed to be deterministic, finalizers by being 
tied to a tracing GC are not. Java doesn't have stack allocated 
objects, but since 1.7 has try-'with resources' and AutoCloseable 
to cover some cases in RAII-like fashion. My terminology is from 
this http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html

IMO, since D has a GC, and stack allocated structs, it would make 
sense to use different terms for destruction and finalization, so 
what you really want is to properly implement finalizers in your 
GC.
I'm a lot more reluctant to use classes in D now, and I'd like to 
see a lot more code with @nogc or compiled with a the previously 
discussed and rejected no runtime switch.

Interestingly, Ada finalization via 'controlled' types is 
actually what we call destructors here. The Ada approach is 
interesting, but I don't know if a similar approach would fit 
well with D, which is a much more pointer intensive language.




More information about the Digitalmars-d mailing list