[Gc] Re: How to use finalization

Hans Boehm Hans.Boehm at hp.com
Mon Jun 12 20:44:06 PDT 2006


Unordered finalization becomes considerably safer if you set
GC_java_finalization, which adds an extra mark pass to prevent objects
reachable from finalizable objects from being reclaimed.  Nonentheless, I
would normally recommend the default ordered finalization, unles you have
a language spec that tells you otherwise.

Als not theat the default is to run finalizers from the allocator instead
of in a different thread.  That's safe only for some really simple
finalizers.

Hans

On Mon, 12 Jun 2006, Juan Jose Garcia Ripoll wrote:

> On Mon, 2006-06-12 at 16:09 +0200, Ludovic Courtès wrote:
> > Basically, you need to call `GC_REGISTER_FINALIZER_NO_ORDER ()' and then
> > you are allowed to do a lot of things from within the finalizer: create
> > new objects, new references to the object being destroyed, etc.
>
> Yes, this is what I thought, but then I got this email from one of the
> developers:
>
> > In my first trial, I used GC_register_finalizer_no_order and made
> > a test on a string object, with:
> >
> > (let ((x "hello")) (si:finalize x #'myfun) (print x))
> >
> > Then I found out that when the string object got finalized, the char
> > array associated with it was already GC, leaving just garbage in it.
> > Then I looked in the gc.h for some doc and found out that using
> > GC_register_finalizer could avoid that problem ("if a points to b ...").
>
> So he ended up using GC_register_finalizer() which is what I used in
> other parts of the library that are not exposed to the lisp environment.
>
> I will have a look later at the thread you point to. Gmane seems to be
> off-line right now.
>
> Juanjo
>
>



More information about the Gc mailing list