diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-12-04 10:21:06 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-12-04 10:21:06 +1000 |
commit | 40547cd02aeb8bbd3682a281d8a1c5afcab782ee (patch) | |
tree | 4dd75b760d7ac63a2881f12187a4b94db1f5be6a /src/library | |
parent | 9483542b1304601683fbda0fee1eef1c8c10696a (diff) | |
parent | 0bb8a139e9c46e3e1b4bd7af5dd11cb689ebbe8e (diff) | |
download | scala-40547cd02aeb8bbd3682a281d8a1c5afcab782ee.tar.gz scala-40547cd02aeb8bbd3682a281d8a1c5afcab782ee.tar.bz2 scala-40547cd02aeb8bbd3682a281d8a1c5afcab782ee.zip |
Merge pull request #4061 from maxcom/SI-8924-list-iterator-oom
SI-8924 don't hold reference to list in iterator
Diffstat (limited to 'src/library')
-rw-r--r-- | src/library/scala/collection/LinearSeqLike.scala | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/library/scala/collection/LinearSeqLike.scala b/src/library/scala/collection/LinearSeqLike.scala index 3288599221..96e2135fd1 100644 --- a/src/library/scala/collection/LinearSeqLike.scala +++ b/src/library/scala/collection/LinearSeqLike.scala @@ -46,12 +46,18 @@ trait LinearSeqLike[+A, +Repr <: LinearSeqLike[A, Repr]] extends SeqLike[A, Repr val result = these.head; these = these.tail; result } else Iterator.empty.next() - /** Have to clear `these` so the iterator is exhausted like - * it would be without the optimization. - */ override def toList: List[A] = { + /* Have to clear `these` so the iterator is exhausted like + * it would be without the optimization. + * + * Calling "newBuilder.result()" in toList method + * prevents original seq from garbage collection, + * so we use these.take(0) here. + * + * Check SI-8924 for details + */ val xs = these.toList - these = newBuilder.result() + these = these.take(0) xs } } |