[racket] interactive.rkt

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Oct 14 07:53:36 EDT 2010

At Wed, 13 Oct 2010 21:39:42 -0400, Eli Barzilay wrote:
> > I'm curious why does time** start by doing 3 (collect-garbage) calls
> > in a row?
> 
> I don't remember whether it was weak pointers or will executors that
> can require two GCs (maybe both do).  And as long as it's GCing
> explicitly, it can just as well run another one...

In general, finalizers can require N iterations, because a finalizer
callback can be a closure that references another value that has a
finalizer, and so on. After a finalizer is run, any value that it
references will not be queued for finalization until the next GC.

For the internal finalizers, especially the ones in the current
`racket/gui' implementation, and two `(collect-garbage)' calls is
usually enough to get those out of the way.

If your finalizers queue callbacks to a will executor, then two
`(collect-garbage)' calls right in a row probably isn't good enough,
because some thread work with the will executor to run the callbacks.

Still, if `(collect-garbage)' queues any finalizers --- whether to will
executors or interally --- then the garbage collector schedules another
major collection in the hope of cleaning up formerly finalized data.
So, a second `(collect-garbage)' can get that additional major
collection out of the way.

A third `(collect-garbage)' offers diminishing returns, but it might do
something and it doesn't particularly hurt.



Posted on the users mailing list.