Why does the following code (taken from regression/weak.2.sml) return true, and more importantly why is it supposed to return true (according to the expected test result in weak.2.ok):<br><br>structure Weak = MLton.Weak<br>
<br>val x = (13, ref 5)<br>val wx = Weak.new x<br>fun isAlive () = isSome (Weak.get wx)<br>val _ = MLton.GC.collect ()<br>val _ = print (Bool.toString (isAlive ()) ^ &quot;\n&quot;)<br><br>Shouldn&#39;t x be garbage collected?<br>
I&#39;m having a play with multiMLton branch of MLton and this test fails there as it returns false, but that makes more sense as x doesn&#39;t seem to be reachable from anything.<br>Similar code in SML/NJ also returns false:<br>
<br>Standard ML of New Jersey v110.72 [built: Wed Jan 26 00:56:21 2011]<br>let<br>    val x = (13, ref 5)<br>    val wx = SMLofNJ.Weak.weak x<br>    fun isAlive () = isSome (SMLofNJ.Weak.strong wx)<br>in<br>    SMLofNJ.Internals.GC.doGC 100000<br>
  ; print (Bool.toString (isAlive ()) ^ &quot;\n&quot;)<br>= end;<br>[autoloading]<br>[library $SMLNJ-BASIS/<a href="http://basis.cm">basis.cm</a> is stable]<br>[autoloading done]<br>false<br>val it = () : unit<br>