[Gc] gc callbacks

Bruce Hoult bruce at hoult.org
Fri Apr 15 04:13:15 PDT 2011

On Fri, Apr 15, 2011 at 10:29 PM, Andy Wingo <wingo at pobox.com> wrote:
> Hello list,
> I would like to get a callback when GC runs.  I was doing this with
> finalizers:

Bad idea.

There is no guarantee that any given finalizer is ever run. Finalizers
need only be run prior to that memory being rellocated for another new
object. Even if there are no references to the object the finalizer
need not be run if an object of that size is not needed again, or if
the program terminates.

The current GC implementation does try to run available finalizers at
the end of a GC invocation but that might not happen.

If you want to know when a full collection starts then set up GC_start_call_back

More information about the Gc mailing list