diff options
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 ff7985bf0d..6fb452797e 100644 --- a/src/library/scala/collection/LinearSeqLike.scala +++ b/src/library/scala/collection/LinearSeqLike.scala @@ -58,12 +58,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 } } |