Destructors calling sequence

Michael pr at m1xa.com
Sat Nov 30 12:45:01 PST 2013


> class A
> {
>    bool reset;
>    void delegate dtor();
>    ~this()
>    {
>       if (!reset)
>          dtor();
>    }
> }
>
> class B
> {
>    A a;
>    bool run;
>    ~this() { if (!run) a.reset = true; run = true; }
> }
>
> A a = new A;
> B b = new B;
> b.a = a;
> b.a.dtor = & b.__dtor;

relying on to "bool reset" it's no good idea.

In this case a manual memory management - good choice.



More information about the Digitalmars-d-learn mailing list