clasp
clasp copied to clipboard
Weak hash tables: Symbols are garbage collected too early, even if they have a reference
(progn
(defvar *key-store* nil)
(defvar *test-weak-table* (make-hash-table :test #'eq :weakness :key))
(dotimes (x 5)
(let ((sym (make-symbol (princ-to-string x))))
(pushnew sym *key-store*)
(setf (gethash sym *test-weak-table*)(list x (1+ x)))))
(setq * nil ** nil *** nil)
(dotimes (x 10)(gctools:garbage-collect))
(pprint *key-store*)
(maphash #'(lambda(key value)
(print `(,key ,value))) *test-weak-table*)
(setq *key-store* nil)
(dotimes (x 10)(gctools:garbage-collect))
(maphash #'(lambda(key value)
(print `(,key ,value))) *test-weak-table*)
)
(#:|4| #:|3| #:|2| #:|1| #:|0|)
(0 (2 3))
(0 (4 5))
(0 (3 4))
(0 (3 4))
(0 (0 1))
(0 (0 1))
(0 (4 5))
(0 (1 2))
(0 (2 3))
(0 (2 3))
(0 (4 5))
(0 (3 4))
(0 (3 4))
(0 (0 1))
(0 (0 1))
(0 (4 5))
(0 (1 2))
This might not happen in all installations, e.g. drmeister does not seem to observe this
#936 also happens here
- Does not seem to happen with MPS.
- Since neither Bike nor drmeister seem to have the same issue, it might depend on the bdw-gc version being installed.
- with `brew info bdw-gc´ we should get the version
now gives: `(#:|4| #:|3| #:|2| #:|1| #:|0|)
NIL`
this seems to be correct
(progn
(defvar *key-store* nil)
(defvar *test-weak-table* (make-hash-table :test #'eq :weakness :key))
(dotimes (x 5)
(let ((sym (cons x x)))
(pushnew sym *key-store*)
(setf (gethash sym *test-weak-table*)(list x (1+ x)))))
(setq * nil ** nil *** nil)
(dotimes (x 10)(gctools:garbage-collect))
(pprint *key-store*)
(maphash #'(lambda(key value)
(print `(,key ,value))) *test-weak-table*)
(setq *key-store* nil)
(dotimes (x 10)(gctools:garbage-collect))
(maphash #'(lambda(key value)
(print `(,key ,value))) *test-weak-table*)
)
((4 . 4) (3 . 3) (2 . 2) (1 . 1) (0 . 0))
((3 . 3) (3 4))
((1 . 1) (1 2))
((2 . 2) (2 3))
((0 . 0) (0 1))
((4 . 4) (4 5))
NIL