Hi Dr. Dias,
a WeakValueDictionary get's its values collected if they are not referenced strongly. However, the association remains there. This means that when you do:
dictionary := WeakValueDictionary with: 'hello' -> nil copy.
You'll have something like this:
WeakValueDictionary {
�� WeakValueAssociation { key: 'hello', value: yourObject }
}
Once you garbage collect, the value is holding yourObject weakly, so you'll have:
WeakValueDictionary {
�� WeakValueAssociation { key: 'hello', value: nil }
}
But the WeakValueAssociation will still be there.
Apparently, what you want to do is to automatically clean your dictionary. Checking a Pharo60371, I see that WeakValueDictionaries do not implement this... But WeakKeyDictionary does.
Take for example a look at WeakKeyDictionary>>finalizeValues. If you subscribe the WeakKeyDictionary instance to the WeakRegistry, the weak registry will send finalize values to your weak key dictionary and they will eliminate the expired associations. However, #finalizeValues is not implemented in WeakValueDictionary. Maybe we should?
Or maybe you should try with Ephemerons.
Guille
BTW why are you using a copy of nil? you can test it with a plain new Object (i.e., Object new). It took me a couple of extra seconds to realize what you were doing.