What is legal in a destructor?

Lutger lutger.blijdestijn at gmail.com
Sun Aug 27 04:09:47 PDT 2006

I'm having some trouble understanding exactly what is and what isn't 
legal to do in a (non-auto) destructor. I'm thinking about these 

- using the 'this' pointer as a parameter to make calls to another (from 
another class or free) function.
- calling member functions.
- referencing delegates to member functions.
- referencing data fields with types like int.

Also, is there a way to have the garbage collector run and collect dead 
objects without the delete expression, so as to experiment with the 

The spec says: "When the garbage collector calls a destructor for an 
object of a class that has members that are references to garbage 
collected objects, those references are no longer valid. This means that 
destructors cannot reference sub objects. This rule does not apply to 
auto objects or objects deleted with the DeleteExpression."

More information about the Digitalmars-d-learn mailing list