[Openmcl-devel] strange(?) hash-table-count on weak hash table

Jared C. Davis jared at cs.utexas.edu
Wed Jun 18 20:19:00 PDT 2014


I was experimenting with weak hash tables and have run into something I don't
understand.  Here's a small example, taken on 1.10-dev-r16074M-trunk


(defparameter *ht* (make-hash-table :weak :key :test 'eq))
(defparameter *key* (cons 1 2))
(setf (gethash *key* *ht*) 17)

(hash-table-count *ht*) ;; 1, as I expected

(hash-table-count *ht*) ;; 1, as I expected since *key* is obviously reachable

nil ;; try to clear out *, **, ***

(hash-table-count *ht*) ;; 1, as I expected since *key* is still reachable
(setf *key* nil)        ;; The (cons 1 2) should now be unreachable, right?
(gc)                    ;; So this should free the hash table entry

(hash-table-count *ht*) ;; 2 --- er, what the heck?!?


I had expected the final line above to report 0 instead of 2.  I wouldn't have
been entirely surprised by a count of 1, but how in the world did the count
increase?  Is this expected?


Jared C. Davis <jared at cs.utexas.edu>
11410 Windermere Meadows
Austin, TX 78759

More information about the Openmcl-devel mailing list