On 2011-09-04 14:59, Andrei Alexandrescu wrote:
On 9/4/11 7:11 AM, Jacob Carlborg wrote:
Tango has added a new method to Object, "dispose". The method is called
by the runtime when a scoped class exits a scope:

void foo ()
{
scope f = new File;
}

When "foo" exits File.dispose will be called and it can close any file
handles. I think it's quite clever.

What happens if f is aliased beyond the existence of foo()?

Andrei

I'm not sure if this is what you mean but:

File file;

void foo ()
{
    scope f = new File;
    file = f;
}

void main ()
{
    foo;
    // file is disposed here
}

In the above example "dispose" will be called when "foo" exits. After the call to "foo" in the main function "file" will refer to an object that is disposed, i.e. an object where the "dispose" method has been called.

I don't know how bad this is or if it is bad at all. I would be the same as the following code:

File file;

void foo ()
{
    auto f = new File;
    f.close;
    file = f;
}

void main ()
{
    foo;
}

--
/Jacob Carlborg

Reply via email to