On Saturday, 2 March 2019 at 11:32:53 UTC, JN wrote:
...
Is this proper behavior? I'd imagine that when doing foos.remove("bar"), Foo goes out of scope and should be immediately cleaned up rather than at the end of the scope? Or am I misunderstanding how should RAII work?

https://dlang.org/spec/struct.html#struct-destructor

"Destructors are called when an object goes out of scope. Their purpose is to free up resources owned by the struct object."

Example:

import std.stdio;

struct S
{
    ~this()
    {
        import std.stdio;
        writeln("S is being destructed");
    }
}


void main(){
    {
        S s = S();
        scope (exit)
        {
            writeln("Exiting scope");
        }
    }
    writeln("Ending program.");
}

Output:
Exiting scope
S is being destructed
Ending program.

Matheus.

Reply via email to