On Thursday, 27 February 2014 at 22:04:50 UTC, Namespace wrote:
A struct is a value type. So it is passed by value and is placed on the stack.

{
    S s;
}

S DTor is called at the end of the scope. So you can rely on RAII as long as you use structs.

On the stack yes. But not on the heap:

    S[] s = new S[17];
    s = null;

the GC will collect the memory eventually, but without calling any destructor.

On the other hand:

    class C { S s; }
    C c = new c;
    c = null;

in this case, when the gc collects the memory, it will call both destrcutors. The one of C as well as of S.

Reply via email to