struct S {
    static int count = 0;
    this(int x) { ++count; }
    this(this) { ++count; }
    ~this() { --count; }
}

int main(string[] argv)
{
    S[] x = [S(1), S(1)];
    writeln("GC allocated: ", (GC.addrOf(x.ptr) !is null));
    x = null;
    GC.collect();
    writeln("live objects: ", S.count);
    return 0;
}

output:
GC allocated: true
live objects: 2

expected:
GC allocated: true
live objects: 0

Is this a bug?

I thought that the first writeln() may be leaving a copy of the pointer lingering on the stack somewhere, but the output is still "live objects: 2" with that line commented out.

  Thanks


Reply via email to