collect-regularly.rkt
#lang racket/base

(define collect-thread #f)

(define (collect-regularly (delay 300))
   (when (not collect-thread)
     (set! collect-thread
       (thread
        (λ ()
          (dynamic-wind
           void
           (λ () (let eternity () (collect-garbage) (sleep delay) (eternity)))
           (λ () (set! collect-thread #f))))))))

(provide collect-regularly)