-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix Stream.iterator memory leak #9710
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
Conversation
review by @scala/collections ? |
@@ -8,4 +8,5 @@ object Test extends App { | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).iterator.foreach(_ => ()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did this test fail before the change?
Just making sure we have a test to catch any regression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, fails without the change. OOME.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thank you!
@@ -8,4 +8,5 @@ object Test extends App { | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } | |||
Stream.tabulate(100)(_ => new Array[AnyRef](10000)).collectFirst { case x if false => x } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
late to the party, but why is this line repeated 3 times?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wondered, too. git says two of them were added in https://github.com/scala/scala/pull/9324/files#diff-b0ab17467318c0ab594f748c21870010636257c36577157fcdd7f01836f4b272. The same PR also updated the number of deprecation warnings, so it seems somewhat intentional at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's funny - I have no recollection doing that. Was I trying to stress the GC? Did I do that before changing the java options and then committing? I'd assume some sanity and say it's related to using JDK 15 in some way... Maybe someone wants to try to retrace my steps. I also don't mind if someone wants to remove the extras.
…tor-leak Fix Stream.iterator memory leak
…tor-leak Fix Stream.iterator memory leak
Stream.iterator
kept a reference to the head of the stream which prevented any part of the Stream from getting garbage collected. I suspect this was the underlying cause of similar fixes like #8367. Scala 2.11 is unaffected.This change prevents
LinearSeqIterator
from creating a private field and closing over the head of theStream
as acoll
class field.Before:
After:
I didn't find any open issues on scala/bug for this.