[squeak-dev] WeakIdentityDictionary vs WeakSet

Eliot Miranda eliot.miranda at gmail.com
Sat Jul 23 22:03:59 UTC 2022


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 at 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
>
>

-- 
_,,,^..^,,,_
best, Eliot
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220723/fd467873/attachment.html>


More information about the Squeak-dev mailing list