New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stream.tails leaks memory #10131
Comments
Imported From: https://issues.scala-lang.org/browse/SI-10131?orig=1 |
Moving to backlog because |
|
Welcome to Scala 2.13.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.
scala> def stream = LazyList.continually(new Array[Byte](1024 * 1024))
def stream: scala.collection.immutable.LazyList[Array[Byte]]
scala> stream.tails.take(100000).foreach{_ => }
java.lang.OutOfMemoryError: Java heap space
at $anonfun$stream$1(<console>:1)
at $Lambda$992/447477005.apply(Unknown Source)
at scala.collection.immutable.LazyList$.$anonfun$continually$1(LazyList.scala:1198)
at scala.collection.immutable.LazyList$$$Lambda$998/1867108691.apply(Unknown Source)
at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state$lzycompute(LazyList.scala:230)
at scala.collection.immutable.LazyList.scala$collection$immutable$LazyList$$state(LazyList.scala:223)
at scala.collection.immutable.LazyList.isEmpty(LazyList.scala:240)
|
you are correct; my apologies. assigning to myself to fix the |
|
update: in actuality, it is the implementation of override def tails: Iterator[C] =
Iterator.iterate(coll)(_.tail).takeWhile(_.nonEmpty) ++ Iterator.single(newSpecificBuilder.result()) the last element in the iterator is lazy, but invokes the fix for this problem is to eagerly create the |
this code causes OOME
generated Iterator has reference to underlying stream via calling
newBuilder
https://github.com/scala/scala/blob/v2.12.1/src/library/scala/collection/TraversableLike.scala#L806
The text was updated successfully, but these errors were encountered: