Reddit: SafeD - The Safe Subset of D

Chris Miller chris at dprogramming.com
Tue Mar 25 18:34:36 PDT 2008


> > Finally, would SafeD have to disallow destructors? If you're accessing garbage collected memory in a destructor, you're asking for trouble. It's not always as simple as directly disallowing access these fields. Calling functions can indirectly cause the memory to be accessed. However, if you're not accessing GC memory in a destructor, you're probably using some lower-level functions, which are generally untrustworthy.
> 
> I thought the garbage collector only freed memory after the destructor had been run.
> 
> DMD 1.00 spec document, page 104 says "The garbage collector calls the destructor when the object is deleted."
> 
> Did this change?  I haven't checked for an update to my copy of the spec document in some time.
> 
> -- the "other" Chris Miller

http://www.digitalmars.com/d/2.0/class.html#Destructor

"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 is because that the garbage collector does not collect objects in any guaranteed order, so there is no guarantee that any pointers or references to any other garbage collected objects exist when the garbage collector runs the destructor for an object."

-- 
Chris Miller <chris at dprogramming.com>


More information about the Digitalmars-d-announce mailing list