On Monday, 28 October 2013 at 10:07:15 UTC, Rene Zwanenburg wrote:
On Sunday, 27 October 2013 at 23:33:55 UTC, Ali Çehreli wrote:
That's news to me. I know that objects may never be destroyed but why multiple times? How many lives do they have? ;)

Yeah, I'd like to know this as well. I do remember structs allocated on the heap don't have their destructors called at all due to the GC not being precise, I think.

The fact that structs are movable and there is too few struct runtime reflection makes them noncollectable. However, you can wrap struct inside class, in such case struct dtor will be called.


But one object allowed to be destructed multiple times? That sounds really bad.. If that's true a lot of my code is probably incorrect.

I think one need to be aware of this bug (no dtor), rather than cases when dtor is called multiple times.

import std.stdio;

struct S
{
   int i;
   this(int i)   { writefln("ctor, %X", i); this.i = i; }
   this(this)  { writefln("postblit, %X, %X", &this, i); }
   ~this()     { writefln("dtor, %X, %X", &this, i); }
}

int this_throws() { throw new Exception(""); }

void foo(S s, int i) {}

void main()
{
   try { foo(S(1), this_throws); }
   catch(Exception e) {}
}

Reply via email to