Say I have a Stream that’s rather expensive to compute. I can easily create a thread that “computes ahead” just by writing something like
import scala.actors.Futures._
val s = future { stream.size }
If I then throw away the reference to this Future, will that thread be killed off by the garbage collector?
No. The thread belongs to the scheduler. In any case, the scheduler has a reference to the body un-finished Future (this happens in
a.start()), so it won’t be garbage collected before completion.