[Issue 2834] Struct Destructors are not called by the GC, but called on explicit delete.

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Thu Jul 3 18:03:02 PDT 2014


https://issues.dlang.org/show_bug.cgi?id=2834

Jonathan M Davis <jmdavisProg at gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jmdavisProg at gmx.com

--- Comment #13 from Jonathan M Davis <jmdavisProg at gmx.com> ---
I'd strongly argue that we make it so that struct destructors get called when
the memory for a struct is freed on the GC heap (though that pretty requires
what precise heap scanning requires as Sean points out). However, it should be
pointed out that there's no guarantee (and likely never will be a guarantee)
that everything on the heap will be collected, which would mean that it will
never be guaranteed that all struct destructors will be called when on the heap
- just that they would be called in the cases where the struct is collected and
freed by the GC.

So, while we should be able to make it so that struct destructors on the GC
heap get called much more (as opposed to never), it will almost certainly be
the case that the non-GC heap (along with some kind of manual memory management
or reference-counting) will have to be used if it's _required_ that the
destructor be run (though technically, not even that would guarantee it, since
the program could still segfault, or an Error could be thrown, or the computer
could lose power or some other incident could occur which would make it so that
the program terminated prematurely, in which case, the destructors wouldn't be
run).

--


More information about the Digitalmars-d-bugs mailing list