Understanding the GC

Mike Parker aldacron at gmail.com
Wed Jan 30 00:21:53 PST 2013


The take-home point of all of this is that you shouldn't rely on 
destructors for resource deallocation. You could do it in by 
manually destructing objects when you are finished with them (via 
the destroy() method), but then you have to be extra careful 
about class members, ownership, order of destruction, and all of 
that. I find that it's much simpler if I give each of my objects 
a specific cleanup method that releases its own resources. When 
an object is no longer needed, I call its cleanup method and 
clear any references to it. This ensures that system resources or 
whatever are released in a predictable order and I don't run into 
odd crashes from trying to release something that's no longer 
valid. The GC takes care of the rest.


More information about the Digitalmars-d-learn mailing list