bug#77374: eval causes temporary modules to leak memory

nathan via "Bug reports for GUILE, GNU's Ubiquitous Extension Language" <[email protected]> Sun, 30 Mar 2025 01:08:51 +0000
Newsgroups gmane.lisp.guile.bugs
Message-ID <[email protected]>
You can call make-module (from boot-9.scm) as much as you want to create empty modules.
Memory won't leak.

As soon as you call eval with that module, it seems it can't be garbage collected anymore.

This bug also appears as part of the (@ (rnrs eval) environment) procedure because it uses both of those.

Try it out:
(format #t "kb: ~a\n" (floor (/ (assoc-ref (gc-stats) 'heap-size) 1024)))
(let lp ((x 0))
   (unless (eqv? x 50000)
     (let ((m (make-module)))
       (eval '1 m) ;; comment this line to remove memory leak
       2)
     (lp (1+ x))))
(gc)
(format #t "kb: ~a\n" (floor (/ (assoc-ref (gc-stats) 'heap-size) 1024)))