GC object finalization not guaranteed

Leandro Lucarella llucax at gmail.com
Sat Apr 18 14:03:11 PDT 2009


Fawzi Mohamed, el 18 de abril a las 22:48 me escribiste:
> On 2009-04-18 22:25:32 +0200, Don <nospam at nospam.com> said:
> 
> >Leandro Lucarella wrote:
> >>Robert Jacques, el 18 de abril a las 11:56 me escribiste:
> >>>On Sat, 18 Apr 2009 11:24:14 -0400, Leandro Lucarella <llucax at gmail.com> wrote:
> >>>>I've just found out[1] this[2]:
> >>>>	The garbage collector is not guaranteed to run the destructor for
> >>>>	all unreferenced objects.
> >>>>Is there any reason why D can't guarantee that all finalizers will be
> >>>>called, at least when the program ends?
> 
> when the main thread ends other threads might be running, and removing
> memory they are using is not necessarily a good idea.

Then I guess gc_term() should be invoked when all threads have terminated.
Is there any technical difficulty to do that?

> Exceptions might delay things indefinitely and allocate more memory.

Then I guess gc_term() should be invoked when all exceptions were
processed. Is there any technical difficulty to do that?

I really didn't take a look at the compiler runtime stuff, so I don't
really know how all that works.

> Actually with tango you can tweak what will happen with
> gc_getTermCleanupLevel (in gc.d), but I don't think that there is
> a satisfying solution for everybody.

Yes, I saw that (I commented about that in the blog post), but there is
still no option to run the finalizers to all the live objects.

Anyways, I wonder why it's not part of the GC specs in druntime.

> I think that the default in tango is quite reasonable (normal collect).

Yes... With the current specs at least, I guess.

I think that if finalization is not guarantee, at least at
program exit, there shouldn't be there. It's useless.

Finalization should be possible only for scope classes if no finalization
guarantee can be provided by the GC. It's useless and error prone
(introducing a bug very difficult to track). Who wants randomly executed
destructors?

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
Mi infancia fue en un loft, bien al costado del río
Cazabamos correcaminos y lo azabamos en el fogón
Después? Después me vine grande y la ciudad me deslumbró
Jugando al tejo en Lavalle me hice amigo del bongó



More information about the Digitalmars-d mailing list