Destructing Member Objects

Simen Kjaeraas simen.kjaras at gmail.com
Sun Apr 6 01:52:06 PDT 2008


On Sun, 06 Apr 2008 06:27:52 +0200, Jarrett Billingsley  
<kb3ctd2 at yahoo.com> wrote:

> The spec doesn't really specify _why_ destruction order is  
> nondeterministic,
> however.  You need nondeterministic destruction in order to break cycles.
> So if A points to B and B points to A, you have a cycle.  In order to  
> break
> the cycle you have to delete one or the other first.  There's no  
> "correct"
> order to destroy them.  So, to solve this, you simply cannot guarantee  
> that
> when an object's destructor is run, that everything that it points to is
> still valid.

It's worth noting that even if only one object in a relation points to
another (i.e. no cycle), the easiest thing for the GC to do is to flag both
as trash, then destroy them in some order when it gets to that point. If it
were to flag only the mother class and destroy that, its child classes  
might
have to wait until the next GC run before they're deleted.

-- Simen


More information about the Digitalmars-d-learn mailing list