Classes or stucts :: Newbie

Andrej Mitrovic andrej.mitrovich at gmail.com
Sun Dec 19 17:03:37 PST 2010


On 12/20/10, Nick Voronin <elfy.nv at gmail.com> wrote:
> I see two aspects there: first is having destructor called at known point
> rather than arbitrarily, second is performance.
>

There's still an alternative for the first part, scope(exit):

import std.stdio;

class A
{
    ~this()
    {
        writeln("A.dtor");
    }
    void test()
    {
        writeln("test");
    }
}

void main()
{
    A a = new A();
    scope(exit)
    {
        clear(a);
    }
    a.test();
}

> test
> A.dtor
> A.dtor


More information about the Digitalmars-d-learn mailing list