[MLton-user] Weak pointer regression test 2

Ivan Tomac ivan.tomac at gmail.com
Thu Apr 14 07:03:11 PDT 2011


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):

structure Weak = MLton.Weak

val x = (13, ref 5)
val wx = Weak.new x
fun isAlive () = isSome (Weak.get wx)
val _ = MLton.GC.collect ()
val _ = print (Bool.toString (isAlive ()) ^ "\n")

Shouldn't x be garbage collected?
I'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't seem to be
reachable from anything.
Similar code in SML/NJ also returns false:

Standard ML of New Jersey v110.72 [built: Wed Jan 26 00:56:21 2011]
let
    val x = (13, ref 5)
    val wx = SMLofNJ.Weak.weak x
    fun isAlive () = isSome (SMLofNJ.Weak.strong wx)
in
    SMLofNJ.Internals.GC.doGC 100000
  ; print (Bool.toString (isAlive ()) ^ "\n")
= end;
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
false
val it = () : unit
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mlton.org/pipermail/mlton-user/attachments/20110415/913d5e67/attachment.html


More information about the MLton-user mailing list