[racket] Periodic calls to collect-garbage?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Sat Jul 16 17:44:48 EDT 2011

[I've been away from the computer]

The Web server does this so that requests don't cause the GC to run
and create a pause. Instead, the GC is always possibly running so that
it will run when the server isn't being accessed. That's the idea at
least. I didn't do very involved experiments to see that it was a good
idea. I found anecdotally that it helped around submission times with
the Continue server.


2011/7/14 Greg Hendershott <greghendershott at gmail.com>:
> 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?
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.