[Issue 2858] D specs allow GC implementations that don't call finalizers

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 19 16:41:04 PDT 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2858





------- Comment #4 from llucax at gmail.com  2009-04-19 18:41 -------
(In reply to comment #1)
> > To fix this, several paths can be taken:
> > 1) Guarantee finalization, at least at program end
> > 2) Remove finalizers completely from the collection (leaving them for use only
> > with deterministic destruction, scope, delete, etc.)
> 
> This would destroy a significant portion of GC's usefulness and break various
> GUI libraries.

I guess you're talking about the 2nd option.

> > The specs should be changed to say something like:
> > 
> >     The garbage collector is guaranteed to run the destructor for all
> >     unreferenced objects, at least at programs exit. At program exit, all
> >     destructors are called, for referenced and unreferenced objects.
> 
> So it could wait until program exit before running _any_ destructors?  Where
> would it keep the objects it collects in the meantime in order that it can run
> the destructors on exit?

You are right, that leaves the GC implementor the option to defer finalization
for all objects until the program exits.

> Perhaps better:
> 
>     The garbage collector runs the destructor for all unreferenced objects 
>     before freeing their memory.

At program exit the memory usually don't need to get freed, so this suggests
that memory should be freed always, which I don't think it's a good idea. It
also implies that destructors are only called for unreferenced objects, and I
think that at program exit, the destructor for all live objects should be
called (references or not).

That's why I think something like this could be more accurate:

    The GC runs the destructor of an object as soon as it detects the object
    is not used any more. This usually happens when: the delete operator is
    used, when collecting unreferenced memory or at program exit. At program
    exit, all destructors are called, for referenced and unreferenced 
    objects. All objects are guaranteed to get their destructor called.

> followed by either the second sentence of your proposed rewrite or this:
> 
>     However, destructors are not guaranteed to be run on program exit, but 
>     the programmer can force them to be run by calling gc_term() immediately 
>     before termination of the program.

Why do you think is a good idea not to guarantee the destructors to be called
at program exit?


-- 



More information about the Digitalmars-d-bugs mailing list