Destructor semantics

Michel Fortin michel.fortin at michelf.com
Tue Aug 10 16:07:31 PDT 2010


On 2010-08-10 18:51:24 -0400, Lutger <lutger.blijdestijn at gmail.com> said:

> This is what I proposed, but the other way around and the semantics of 
> ~~this implemented by an interface. If we keep ~this as the finalizer, 
> the language need not to change so it will not impact existing code too 
> much.

Perhaps you're right, but I wonder...

Structs can be on the GC heap too, so structs also need two kinds of 
destructors. And I believe right now much more structs have a 
destructor than classes have one.

So the question becomes: are most struct destructors currently intended 
to be run during collection cycle or they are expected to be called in 
a more deterministic way? I don't have the answer to that 
unfortunately. The only thing I can say is that if a destructor 
accesses the GC-heap through one of its members then it is not suitable 
to be run during a collection cycle. (And most classes, strings, or 
arrays are in GC heap.)


-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/



More information about the Digitalmars-d mailing list