[Ecls-list] Custom finalization (draft)

Goffioul Michael goffioul at imec.be
Thu Jun 1 08:03:32 UTC 2006


> On Wed, 2006-05-31 at 18:11 +0200, Goffioul Michael wrote: 
> > > I tried to implement custom finalization within ECL with 
> the patch 
> > > attached.
> > > It's only a draft, but the few trivial tests I made seems 
> to work. 
> > > What do you think?
> > Here's a version with corrected function names.
> 
> I am not sure about the semantics of finalization in the 
> Boehm-Weiser garbage collector, and in particular whether we 
> are allowed to "cons"

This was also one of my worries: what operations are allowed
during finalization process. Another thing is to make sure that
the data pointer given to the finalizer, which is a cl_object
representing the function, is not GC (especially if you use
a lambda expression). A third thing is there's no special handling
when the object has already a finalizer: I might be wrong, but
registering a finalizer removes the old one, doesn't it?

As I said, it's just a draft, I wouldn't commit it as-is...

> while running the finalizer. Apart from that, you probably 
> want to use GC_register_finalizer_no_order, which is what the 
> Java implementation does, and which deals properly with 
> cyclic structures.
> 
> Would you mind if I send an email to the GC mailing list 
> before committing this patch? Just to make sure.

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

Michael.




More information about the ecl-devel mailing list