[racket] Periodic calls to collect-garbage?

From: Greg Hendershott (greghendershott at gmail.com)
Date: Thu Jul 14 12:47:54 EDT 2011

Once upon a time I noticed the Racket web server has a thread that
calls collect-garbage periodically (e.g. every 5 minutes).

I've discovered I need to do the same, for any program that needs to
run for hours or days.  Otherwise, the program eventually abends: Out
of memory. Sometimes with a "Racket virtual machine error" message.
This is my experience on both Windows 7 and on Linux, with Racket 5.0
and 5.1.1.

As a result the following has become a "magic spell" I now throw into
such programs:

;; Make a thread to do garbage collection every 5 minutes.
(thread
 (lambda ()
   (let loop ()
     (sleep (* 5 60))
     (collect-garbage)
     (loop))))

It seems weird to have such a magic spell, and to know it only from
nosing around the web server source.

Instead, maybe the Racket runtime should do this automatically (at
least by default)? I think that's people would expect coming from some
other language environments with GC (at least it's what I expected).

Or, at least it would be documented that this is by-design (say for
performance reasons, or there's no reasonable default, or whatever),
and that people should use such a magic spell for long-running
systems?


Posted on the users mailing list.