Odd Destructor Behavior

anonymous via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Feb 7 14:35:57 PST 2016


On 07.02.2016 23:07, Márcio Martins wrote:
> The destructor you are seeing is from the assignment:
>
> m_tileView = TileView(...);
>
> This creates a temporary TileView, copies it to m_tileView, and then
> destroys it. I suppose you want to move it instead. You need to copy the
> handles from the temporary into the destination, and then clear them out
> from the temporary to prevent them from being released.

I think you're mistaken here. The result of a struct literal is usually 
moved implicitly.

Code:
----
import std.stdio;

struct S
{
     ~this() {writeln("dtor");}
}

void main()
{
     auto s = S();
     writeln("end of main");
}
----

Output:
----
end of main
dtor
----

If there was a copy that's destroyed after the assignment, there should 
be another "dtor" before "end of main".


More information about the Digitalmars-d-learn mailing list