Re: Weakness of "non-object" types Takashi Kato 04 Dec 2015 14:27 UTC

> So from the programmer's perspective, the object never disappears; a new
> reference to it can be created any time, even if its memory address
> changed, so it would be strange for a hash table to drop an association
> for that object.
I understand the purpose and indeed it might look weird to programmers if
they don't know how the memory management of the implementation works.
However, IMO, weak hashtable shouldn't hold implicit strong reference if
it's specified to hold as weak reference by users. One of my expected
behaviour is the following (suppose symbols are GCable)

;; suppose nobody holds symbol 'foo
(define wh (make-eq-hashtable 16 (weakness weak-key)))
(hashtable-set! wh (string->symbol "foo") #t)
;; do something causes GC.
;; (gc)
(hashtable-ref wh (string->symbol "foo") 'gone)
;; -> gone (if symbol 'foo is already GCed)

If users want to make sure the symbol 'foo is kept after GC, then they should
make other storage to store it. I think it's more consistent and clearer than
introducing implicit strong reference semantics.

Cheers,

_/_/
Takashi Kato
Email: xxxxxx@ymail.com