<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;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="Signature">
<div id="divtagdefaultwrapper" 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" style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:; margin:0">
<div>
<div class="_rp_T4" id="Item.MessagePartBody">I first need to send #finalizeValues to the dictionary to clean up the array.
<div class="_rp_U4 ms-font-weight-regular ms-font-color-neutralDark rpHighlightAllClass rpHighlightBodyClass" id="Item.MessageUniqueBody" style="font-family:wf_segoe-ui_normal,"Segoe UI","Segoe WP",Tahoma,Arial,sans-serif,serif,EmojiFont">
<div dir="ltr">
<div id="divtagdefaultwrapper"><font face="Calibri,Helvetica,sans-serif,EmojiFont,Apple Color Emoji,Segoe UI Emoji,NotoColorEmoji,Segoe UI Symbol,Android Emoji,EmojiSymbols">
<div id="Signature">
<div style="margin:0px"><font style="font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont"></font></div>
</div>
</font></div>
</div>
</div>
</div>
<div class="_rp_T4" id="Item.MessagePartBody"><br>
</div>
<div class="_rp_T4" id="Item.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 class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><br>
</span></div>
<div class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;">The following would achieve that:</span></div>
<div class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><br>
</span></div>
<div class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><span>WeakArray addWeakDependent: d.</span><br>
</span></div>
<div class="_rp_T4" id="Item.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 class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><span><br>
</span></span></div>
<div class="_rp_T4" id="Item.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 class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><span><br>
</span></span></div>
<div class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><span>Best,</span></span></div>
<div class="_rp_T4" id="Item.MessagePartBody"><span style="font-size: 12pt;"><span>Christoph</span></span></div>
</div>
<div><font size="2" color="#808080"></font></div>
</div>
</div>
</div>
</div>
</body>
</html>