<div dir="ltr">Hi Christoph,<div><br></div><div>Have you read the thread "Improving WeakKeyDictionary comment"? ;-)</div><div><br></div><div>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.</div><div><br></div><div>Kind regards,</div><div>Jakob</div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Am Di., 12. Juli 2022 um 17:55 Uhr schrieb Thiede, Christoph <<a href="mailto:Christoph.Thiede@student.hpi.uni-potsdam.de" target="_blank">Christoph.Thiede@student.hpi.uni-potsdam.de</a>>:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">




<div dir="ltr">
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796divtagdefaultwrapper" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p>Hi all,</p>
<p><br>
</p>
<p>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:</p>
<p><br>
</p>
<p></p>
<div>d := WeakKeyDictionary new.</div>
<div><span style="font-size:12pt">d at: Morph new put: 42.</span><br>
</div>
<div><span style="font-size:12pt"></span></div>
<div>d keys. "#()"</div>
<div>d instVarNamed: 'array'. "{nil->nil . nil . nil . nil . nil->42}"</div>
<br>
<p></p>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Signature">
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796divtagdefaultwrapper" dir="ltr" style="font-size:12pt;color:rgb(0,0,0);font-family:Calibri,Helvetica,sans-serif,EmojiFont,"Apple Color Emoji","Segoe UI Emoji",NotoColorEmoji,"Segoe UI Symbol","Android Emoji",EmojiSymbols">
<div name="divtagdefaultwrapper">
<div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody">I first need to send #finalizeValues to the dictionary to clean up the array.
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796divtagdefaultwrapper"><font face="Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont"></font></div>
</div>
</font></div>
</div>
</div>
</div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><br>
</div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody">Now my question is, is - or should be - every client of a WeakKeyDictionary <span style="font-size:12pt">expected to care about finalization themself, or should these dictionaries be added to a weak registry or
 the finalization process of WeakArray automatically?</span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><br>
</span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt">The following would achieve that:</span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><br>
</span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span>WeakArray addWeakDependent: d.</span><br>
</span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span>Maybe one could also set up a WeakRegistry manually, but I didn't figure out yet how to do this.</span></span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span><br>
</span></span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span>Should I append this code to any of my code that creates a WeakKeyDictionary, or should this happen inside its constructor already?</span></span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span><br>
</span></span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span>Best,</span></span></div>
<div id="gmail-m_-8527359159434860600gmail-m_-6658285624677494796Item.MessagePartBody"><span style="font-size:12pt"><span>Christoph</span></span></div>
</div>
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
</div>

<br>
</blockquote></div>