On Friday, 2 August 2019 at 23:13:10 UTC, realhet wrote:
Today I read the documentation about structs, unions and
classes, but I haven't find any restrictions for the ~this()
destructors.
Is there some extra rules regarding the GC and what I must not
do in the destructors?
Class destructors are similar to Java's finalizers in behavior. D
doesn't give you a guarantee when the class destructor is called
and it doesn't give you a guarantee if it will be called at all,
so it doesn't really work for RAII-like resource management. If
you want RAII-like behavior, either use structs (struct
destructors are deterministic), or wrap your class inside a
scoped/refCounted wrapper from std.typecons.