Odd behavior found in GC when terminating application

H. S. Teoh hsteoh at quickfur.ath.cx
Fri Jan 5 15:26:00 UTC 2018


On Fri, Jan 05, 2018 at 03:26:03PM +0000, 12345swordy via Digitalmars-d wrote:
> On Friday, 5 January 2018 at 14:35:44 UTC, Jonathan M Davis wrote:
> > On Friday, January 05, 2018 14:29:41 Adam D. Ruppe via Digitalmars-d
> > wrote:
> > > [...]
> > 
> > Either that or use structs on the stack instead of classes on the
> > heap so that you're actually using destructors instead of
> > finalizers.
[...]
> There been discussions regarding spiting up the destruction and finalizers.

Yeah, the GC does not guarantee any particular order that finalizers
will be called.  If you need to ensure a particular order, you'll need
to either do it yourself, or use a refcounting scheme like RefCounted
and set it up so that the last references go away in the right order.

Lately, I've been moving towards using RefCounted for things that need
deterministic destruction or things that need to be finalized in some
specific order.  The GC is more for objects that don't need any special
action when they're collected.


T

-- 
Knowledge is that area of ignorance that we arrange and classify. -- Ambrose Bierce


More information about the Digitalmars-d mailing list