Subject: Weak sets keep growing

From: Ludovic Courtès <[email-masked]>
Date: Mon, 23 Mar 2020 15:17:46 +0100

Hello,

Consider this code:

--8<---------------cut here---------------start------------->8---
(define (create-symbols)
  (let loop ((i 10000))
    (unless (zero? i)
      (gensym)
      (loop (1- i)))))

(let loop ((i 10))
  (unless (zero? i)
    (pk i (%symbols))
    (create-symbols)
    (loop (1- i))))
--8<---------------cut here---------------end--------------->8---

(You need to have the ‘%symbols’ procedure from libguile/symbols.c
compiled in.)

In 3.0.1+, it prints:

--8<---------------cut here---------------start------------->8---
;;; (10 #<weak-set 3517/7027>)

;;; (9 #<weak-set 10271/14051>)

;;; (8 #<weak-set 11625/28099>)

;;; (7 #<weak-set 21625/28099>)

;;; (6 #<weak-set 11090/56197>)

;;; (5 #<weak-set 21090/56197>)

;;; (4 #<weak-set 31090/56197>)

;;; (3 #<weak-set 41090/56197>)

;;; (2 #<weak-set 5052/112363>)

;;; (1 #<weak-set 15052/112363>)
--8<---------------cut here---------------end--------------->8---

The size of the weak set keeps growing, even when GC happens.

Conversely, weak tables shrink upon GC.

Ludo’.