[Gc] Question about gc_cleanup
ben.hutchings at businesswebsoftware.com
Mon Oct 31 07:04:26 PST 2005
Miki Tebeka wrote:
>I'm writing a little demo for a presentation about GC I'll give here. (see
>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 $
> /* Make objects inaccesible */
> f1 = NULL;
> f2 = NULL;
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.
More information about the Gc