"Walter Bright"  wrote in message news:[email protected]...

Invariants should be checking the state of the object that it owns, not other objects. I would consider such an invariant invalid.

What?  No.

This is a perfectly valid use of invariants:

class A
{
   B b;
   invariant()
   {
       assert(!b || b.getA() is this);
   }
}

class B
{
   A a;
   A getA() { return a; }
}

ie checking that the two objects reference each other. This will fail if B is destroyed before A's invariant is run.

I don't see why we'd want anything other than
1. Determine which memory objects are unreferenced
2. Run their invariants
3. Run their destructors

Running the invariants while you're part-way through destroying the object graph is just insane.

Reply via email to