[Gc] Question about gc_cleanup

Ben Hutchings ben.hutchings at businesswebsoftware.com
Mon Oct 31 07:04:26 PST 2005


Miki Tebeka wrote:

>Hello All,
>
>I'm writing a little demo for a presentation about GC I'll give here. (see
>attached).
>
>The problem is that it looks like the finalizers aren't called:
>    [13:30] ~/work/gc $g++ -o safefile.exe safefile.cpp -lgc
>    [13:30] ~/work/gc $./safefile.exe 
>    opened safefile.cpp
>    opened safefile.o
>
>    [13:31] ~/work/gc $
>  
>
<snip>

>    /* Make objects inaccesible */
>    f1 = NULL;
>    f2 = NULL;
>  
>
<snip>

This won't work reliably - the compiler can optimise away these writes 
because so far as it can see the variables are never used afterwards.

You should not rely on finalisers ever being called. See Hans Boehm's 
paper "Destructors, Finalizers, and Synchronization" 
<http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html> for a full 
explanation of the difference between destructors and finalisers.

Ben.




More information about the Gc mailing list