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

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Apr 19 09:46:14 PDT 2009


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

           Summary: D specs allow GC implementations that don't call
                    finalizers
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: spec
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: llucax at gmail.com


The D specs says (http://www.digitalmars.com/d/1.0/class.html#destructors):

    The garbage collector is not guaranteed to run the destructor for all
    unreferenced objects.

This means a conforming D implementation can have a GC implementation that
doesn't call finalizers at all (when collecting (delete should call the
finalizer according to the specs), ever.

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.

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

For 2) This can be written in the specs instead of the current paragraph:

    The garbage collector doesn't run the destructor when objects are
collected.

But most D programs relying on destructors being call in the collection will
break (well, they are broken now, but if this is implemented that brokenness
will be exposed).

But much better will be to do 1). 1) is easy to implement too. The call to
gc_term() should be moved outside the try/catch block in the D main() function
and make gc_term() call finalizers for *all* the live objects. There is no need
to run a collection (like it actually does), we don't need to recover free
memory, just call the finalizers. So probably this fix will even even more
efficient than the current approach.

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.


More discussion on the topic:
http://proj.llucax.com.ar/blog/dgc/blog/post/-43101db1
http://www.digitalmars.com/d/archives/digitalmars/D/GC_object_finalization_not_guaranteed_88298.html


-- 



More information about the Digitalmars-d-bugs mailing list