[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 14:14:53 PDT 2009


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


smjg at iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg at iname.com
         OS/Version|Linux                       |All




------- Comment #1 from smjg at iname.com  2009-04-19 16:14 -------
> I think the current situation is the worse it can be. It makes the language
> really weak. The current specs make any current D program using
> non-deterministic finalizers broken.

Indeed.  What's the point of finalizers if you can't use them?

> 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.

> 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?

Perhaps better:

    The garbage collector runs the destructor for all unreferenced objects 
    before freeing their memory.

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.

I presume Runtime.terminate() in D2 would do the same in any case.


-- 



More information about the Digitalmars-d-bugs mailing list