Destruction in D

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Apr 30 13:17:10 PDT 2015


On Thursday, 30 April 2015 at 20:07:11 UTC, bitwise wrote:
> destructors are called on a separate thread, in parallel to the 
> main thread. Is this correct?

Not necessarily. the way the GC works in D today is whenever any 
thread allocates, it runs the GC functions which might do a 
collection. This is where the destructors run, too.

So a destructor may be run by whatever random thread happened to 
run out of memory and triggered the collection cycle.

> What about structs? Are the destructors called when they go out 
> of scope in a C++ RAII fashion, or do they happen on a separate 
> thread too?

structs work basically the same as C++, yes.


I don't know about your third thing...


More information about the Digitalmars-d-learn mailing list