See the following code:

interface A{
}

class B : A{
    this(string name){this.name = name;}
    ~this(){
        writefln("Destructor %s", name);
    }
    string name;
}

void main(){
    B b0 = new B("b0");
    B b1 = new B("b1");

    A a = b0;
    clear(a);

    clear(b1);
}

Output:
Destructor b1

dmd 2.059

Why is the B destructor not invoked in the first clear?

Expected output:
Destructor b0
Destructor b1

Reply via email to