Skip to content

Instantly share code, notes, and snippets.

@kmizu
Created July 24, 2011 23:37
Show Gist options
  • Save kmizu/1103242 to your computer and use it in GitHub Desktop.
Save kmizu/1103242 to your computer and use it in GitHub Desktop.
An example program about a problem in Stream.
object StreamProblem {
def main(args: Array[String]) {
/*
val large = Stream.continually(new Array[Byte](10000000))
//Streamのheadをlargeで参照したままになっているので、
//OutOfMemoryErrorで死ぬ
large take 100 foreach {bytes=>
println(bytes)
}
*/
//OutOfMemoryErrorで死なない
Stream.continually(new Array[Byte](10000000)) take 100 foreach {bytes=>
println(bytes)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment