scala> System.gc()scala> val x = wr.wr.getx: Option[List[Int]] = Some(List(0, 1, 2, 3, 4)) // <<------ should have been None
scala> import scala.ref.WeakReferenceimport scala.ref.WeakReference
scala> val rq = new scala.ref.ReferenceQueue[List[Int]]
rq: scala.ref.ReferenceQueue[List[Int]] = java.lang.ref.ReferenceQueue@2efbfe50
scala> class WR(a: List[Int]) { val wr = new WeakReference(a, rq)}defined class WR
scala> val wr = new WR((0 until 5).toList) //example 1wr: WR = WR@6b931b97
scala> println(wr.wr.get)
Some(List(0, 1, 2, 3, 4))
scala> System.gc()
scala> println(wr.wr.get)None
scala> val wr = new WR((0 until 5).toList) //example 2wr: WR = WR@7675f36f
scala> val x = wr.wr.getx: Option[List[Int]] = Some(List(0, 1, 2, 3, 4))
scala> val x = 3
x: Int = 3
scala> System.gc()
scala> println(wr.wr.get)
Some(List(0, 1, 2, 3, 4))
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for nailing this Jasper-M.
A class (versus case class) is necessary, and if one really wanted to bind variables one could use a var as in:
var x = wr.get.get
x = null
System.gc()
println(wr.get.get) // <---- prints None.
However, the above defeats having a REPL. If one were manipulating 'big-data', then the growing lexical scope from the interactive session would keep holding onto inaccessible values.
Is this a bug?
Is this a bug?