Destructor semantics

Michel Fortin michel.fortin at michelf.com
Wed Aug 11 13:52:04 PDT 2010


On 2010-08-11 16:26:58 -0400, bearophile <bearophileHUGS at lycos.com> said:

> But if the purpose of a destructor is just to help/speedup the 
> deallocation of a RAM resource (like to nullify the links of a tree to 
> speed up the job of the GC) then in my opinion it is acceptable for 
> this destructor to not run deterministically.

Indeed. So it makes sense to have both a destructor and a finalizer, 
because the destructor can sometime speed up things for the GC.

I've made a proposal on the related bug report that reads like this:

---
For instance, instead of having just destructors, we could have destructors
(~this) and finalizers (~~this). A struct with neither can go anywhere, a
struct with a destructor but no finalizer cannot go on the GC-heap,  a struct
with only a finalizer can go anywhere (the finalizer is used as the
destructor), and a struct with both can go anywhere. The finalizer cannot be
made @safe.

Doing this with structs would probably mean allowing only finalizers (~~this)
for classes, which according to my syntax suggestion would break existing code
for class destructors. Perhaps the syntax should be different.
---
<http://d.puremagic.com/issues/show_bug.cgi?id=4621#c6>

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



More information about the Digitalmars-d mailing list