[Issue 1164] Wrong order of memory deallocation

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Dec 27 00:01:13 PST 2016


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

--- Comment #14 from Pieter Penninckx <pieter.penninckx at scarlet.be> ---
(In reply to comment #11)

Woops. You're right. The segfault is caused by an infinite recursion and
probably not by a GC problem. We can avoid the infinite recursion by marking
fun() as private:

class X 
{
    X sibling;
    private bool fun() const { return true;    } // Note: this line changed.
    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;
}

This just runs normally for me. But if I understand comment #13 correctly, this
is just luck and I shouldn't count on it, especially when the runtime is
compiled with the MEMSTOMP option.

--


More information about the Digitalmars-d-bugs mailing list