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

Jakob Reschke jakres+squeak at gmail.com
Tue Jul 12 20:59:23 UTC 2022


Hi Christoph,

Have you read the thread "Improving WeakKeyDictionary comment"? ;-)

So far, Levente and Chris have not reached mutual agreement on what the
recommendation should be. If one answer is always the right one, we may as
well adapt the implementation accordingly if possible. My takeaway so far
is that if you do register your dictionary as a weak dependent,
finalizeValues will be sent fairly often, which may be or not be good
depending on your use case.

Kind regards,
Jakob


Am Di., 12. Juli 2022 um 17:55 Uhr schrieb Thiede, Christoph <
Christoph.Thiede at student.hpi.uni-potsdam.de>:

> 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/a74a387d/attachment.html>


More information about the Squeak-dev mailing list