[squeak-dev] Should WeakKeyDictionarys add themselves to a WeakRegistry?

Thiede, Christoph Christoph.Thiede at student.hpi.uni-potsdam.de
Tue Jul 12 15:55:25 UTC 2022


Hi all,


after working with WeakKeyDictionarys for months in SimulationStudio, I discovered (actually: Marcel pointed out to me) that dereferencing a key from such a dictionary does *not* remove the associated values automatically:


d := WeakKeyDictionary new.
d at: Morph new put: 42.
d keys. "#()"
d instVarNamed: 'array'. "{nil->nil . nil . nil . nil . nil->42}"


I first need to send #finalizeValues to the dictionary to clean up the array.

Now my question is, is - or should be - every client of a WeakKeyDictionary expected to care about finalization themself, or should these dictionaries be added to a weak registry or the finalization process of WeakArray automatically?

The following would achieve that:

WeakArray addWeakDependent: d.
Maybe one could also set up a WeakRegistry manually, but I didn't figure out yet how to do this.

Should I append this code to any of my code that creates a WeakKeyDictionary, or should this happen inside its constructor already?

Best,
Christoph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220712/4ae06b2b/attachment.html>


More information about the Squeak-dev mailing list