[Issue 1164] Wrong order of memory deallocation

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Dec 26 06:03:35 PST 2016


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

--- Comment #13 from safety0ff.bugz <safety0ff.bugz at gmail.com> ---
(In reply to Pieter Penninckx from comment #9)
> 
> Am I right that the garbage collector currently works as follows:


It currently works as follows:

* Mark
* For each unmarked object:
*   Finalize it if necessary
*   If it can be released without overwriting it do so
* For each unmarked unreleased object:
*   release memory of the object

However, you shouldn't rely on this:
http://dlang.org/spec/class.html#destructors

If you recompile druntime with the MEMSTOMP option, the GC and it will write
arbitrary data to finalized memory.

Therefore it follows that referencing GC managed objects from invariants of
other GC managed objects is unadvised.

I think a case could be made for being able to control insertion of invariant
calls in destructors.

--


More information about the Digitalmars-d-bugs mailing list