Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 0.44 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. object StreamProblem {
  2.   def main(args: Array[String]) {
  3.     /*
  4.     val large = Stream.continually(new Array[Byte](10000000))
  5.     //Streamのheadをlargeで参照したままになっているので、
  6.     //OutOfMemoryErrorで死ぬ
  7.     large take 100 foreach {bytes=>
  8.       println(bytes)
  9.     }
  10.     */
  11.     //OutOfMemoryErrorで死なない
  12.     Stream.continually(new Array[Byte](10000000)) take 100 foreach {bytes=>
  13.       println(bytes)
  14.     }
  15.   }
  16. }