[Gc] Questions about finalizers

Bruce Hoult bruce at hoult.org
Thu Apr 26 19:58:44 PDT 2007


On 4/27/07, Lothar Scholz <scholz at scriptolutions.com> wrote:
> Hello,
>
> I'm using "GC_register_finalizer" now in my Eiffel compiler and i
> would like to know:
>
> 1) Can i make any assumption which thread will execute the
>    finalizer code.

Yes.  Any thread that doesn't alloocate memory using the GC is
guaranteed to not run finalizer code.


> 2) Is there some API to let the application do the finalizer calls?

Yes.  The is a FINALIZE_ON_DEMAND compile flag and a
finalize_on_demand runtime flag that contorl this.  If you set this to
true then the GC will not run finalizers and you need to call
GC_invoke_finalizers() yourself.  You can if you like call
GC_should_invoke_finalizers() (which is cheap) to find out whether it
is worth calling GC_iinvoke_finalizers().


>    I would like to do this in a background thread
>    and i would like to optimize the current situation
>    which require to do a slow setjmp operation for any
>    finalizer call (to catch thrown Eiffel exceptions -
>    implemented with setjmp/longjmp)

setjmp is not slow.  Or at least no slower than a function call with
as many arguments as you have callee-save registers in your CPU.


> 4) Are there any optimizations if i can garantee that
>    the objects are never made reachable again by the finalizer?

(untested) You could call GC_free() on the object at the end of the finalizer.


More information about the Gc mailing list