[Issue 1164] Wrong order of memory deallocation

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Dec 25 05:57:10 PST 2016


https://issues.dlang.org/show_bug.cgi?id=1164

--- Comment #7 from Pieter Penninckx <pieter.penninckx at scarlet.be> ---
The following code still segfaults with DMD 2.072.1-0.

class X 
{
    double a, b, c, d, e, f, g, h;
    X sibling;
    bool fun() const { return true;    }
    invariant() {
        if(sibling !is null) {
            if (sibling.fun())
            { assert(true);    }
        }
    }
    this() {sibling = new X(this); }
    this(X sibling_) {sibling = sibling_;}
    ~this() {}
}

int main() {
    X x = new X();
    return 0;
}


Garbage collector + destructor (or finalizer) is a difficult combination. See
for instance this comment
(https://github.com/WebAssembly/design/issues/238#issuecomment-116877193) that
strongly opposes introducing a destructor in Javascript because this
combination can lead to object resurrection (objects made reachable again in a
destructor call).

--


More information about the Digitalmars-d-bugs mailing list