ashinn / chibi-scheme

Official chibi-scheme repository
Other
1.2k stars 142 forks source link

Garbage collection of symbols #488

Open mnieper opened 5 years ago

mnieper commented 5 years ago

The following code causes Chibi to allocate more and more memory:

(do ((i 0 (+ i 1)))
     (#f)
   (symbol->string (string->symbol (number->string i)))
   (when (zero? (modulo i 10000))
     (display (gc))
     (newline)))

Aren't the generated interned symbols garbage-collected?

ashinn commented 5 years ago

Yes, the symbol table implementation predates weak references. We can probably fix this now easily.

mnieper commented 5 years ago

A slight complication may arise when symbols are used as weak keys (for example, in ephemerons). As symbols can always be reforged using string->symbol a symbol weak key may never be invalidated even if the interned symbol is being garbage collected.