Created
July 24, 2011 23:37
-
-
Save kmizu/1103242 to your computer and use it in GitHub Desktop.
An example program about a problem in Stream.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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