weixin_39631755 2020-11-29 13:32
浏览 0

Weak hash tables: Symbols are garbage collected too early, even if they have a reference

lisp
(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)) 

`

该提问来源于开源项目:clasp-developers/clasp

  • 写回答

5条回答 默认 最新

  • weixin_39631755 2020-11-29 13:32
    关注

    This might not happen in all installations, e.g. drmeister does not seem to observe this

    评论

报告相同问题?