forcing "@nogc" on class destructors
    Jerry Morrison via Digitalmars-d 
    digitalmars-d at puremagic.com
       
    Sat Jan 24 15:28:34 PST 2015
    
    
  
This is the first I've heard that allocating GC memory in a 
destructor will crash. That's an unexpected gotcha. I'd expect to 
be able to reliably do I/O or throw an exception.
Strategy 1. Fix the GC's limitation. (One fewer pitfall to 
baby-sit.)
Strategy 2. Have the compiler inform the programmer. (The 
compiler can't catch all bugs but it should do what it can. 
Arguably this is a GC bug, not mine.)
Strategy 3. Put bold warnings in the reference 
<http://dlang.org/class.html#destructors> and all tutorials. 
That's useful but insufficient. Programmers will carry 
assumptions from other programming languages. Even those who read 
the D reference won't all remember that detail when it matters.
Strategy 4. Accept such crashes. (No good. The D home page 
promises safety.)
On Saturday, 24 January 2015 at 15:04:47 UTC, Ola Fosheim Grøstad 
wrote:
> If the classes are written for RAII then the destructors have 
> to be called in reverse order of the constructors. IIRC D does 
> not guarantee this when you use the GC.
>
> So to do it right there is a lot of GC overhead.
Yes, but the usability question is what do programmers expect? 
How much do they assume before turning to the docs?
It's a big stretch to expect LIFO behavior from garbage 
collection. It's not a stretch to expect logging to work.
    
    
More information about the Digitalmars-d
mailing list