Dtors for heap-allocated structs: Bug or by design?

dsimcha dsimcha at yahoo.com
Sun Sep 7 18:04:46 PDT 2008


I've noticed that struct dtors do not get called when a heap-allocated struct
instance is GC'd like they would for a class.  An example is below.  Is this a
bug or is it intentional?

import std.stdio, std.gc;

class foo {

    ~this() {
        writefln(stderr, "foo dtor");
    }
}

struct bar {

    ~this() {
        writefln(stderr, "bar dtor");
    }
}

void main() {  //Prints "foo dtor".  Does not print "bar dtor".
    auto f = new foo;
    f = null;
    auto b = new bar;
    b = null;
    fullCollect;
}



More information about the Digitalmars-d-bugs mailing list