Hello all,
I noticed that a WeakIdentityDictionary does not hold literal values. For example, in a workspace:
wd := WeakIdentityDictionary new. wd at: #foo put: 42. wd at: #bar put: #foo.
wd "printIt ->" a WeakIdentityDictionary()
On the other hand, WeakSet does hold literals
ws := WeakSet new. ws add: #foo. ws add: 42.
ws "printIt ->" a WeakSet(#foo 42)
And also WeakKeyDictionary
wk := WeakKeyDictionary new. wk at: #foo put: 42. wk at: #bar put: #foo.
wk "printIt ->" a WeakKeyDictionary(#bar->#foo #foo->42 )
Is this the intended behavior? What is the semantics here?
Stef
Hi Stéphane,
WeakIdentityDictionary is not the same as WeakKeyIdentityDictionary. Read the class comments. WeakIdentityDictionary refers to its *associations* weakly. Since there are no references to the associations in your dictionary they get GC'ed immediately and you see no contents. I'm guessing that WeakKeyIdentityDictionary is what you want.
On Sat, Jul 23, 2022 at 6:01 AM Stéphane Rollandin lecteur@zogotounga.net wrote:
Hello all,
I noticed that a WeakIdentityDictionary does not hold literal values. For example, in a workspace:
wd := WeakIdentityDictionary new. wd at: #foo put: 42. wd at: #bar put: #foo. wd "printIt ->" a WeakIdentityDictionary()
On the other hand, WeakSet does hold literals
ws := WeakSet new. ws add: #foo. ws add: 42. ws "printIt ->" a WeakSet(#foo 42)
And also WeakKeyDictionary
wk := WeakKeyDictionary new. wk at: #foo put: 42. wk at: #bar put: #foo. wk "printIt ->" a WeakKeyDictionary(#bar->#foo #foo->42 )
Is this the intended behavior? What is the semantics here?
Stef
squeak-dev@lists.squeakfoundation.org