-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fixed resource leak in sootup.java.bytecode.frontend module #1099
Fixed resource leak in sootup.java.bytecode.frontend module #1099
Conversation
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.
thx for your contribution!
.collect(Collectors.toList()); | ||
return javaSootClassSources.stream(); |
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.
please don' t .collect() and .stream() again (return stream directly)
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.
Hi @swissiety since streams are lazy, if we don't collect, we cannot safely close the Stream
returned by Files.walk
within this method (since the filter and map operations won't have been executed yet). The collect
forces those operations to execute, so then the stream can be closed. If you prefer not to collect and then stream again, an alternative would be to require all callers of this method to close the returned stream. Would that be preferable?
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.
thx @msridhar for pointing to that situation! As this is a protected method and its calling contexts are collecting the Stream again i would prefer to close the Stream in the two calling method(s) due to have less allocations
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.
@Bryce7832 could you update the PR to get rid of the collect to a list, and instead use try-with-resources at both callers of this method?
3f25697
to
5b55176
Compare
5b55176
to
a7bb4f8
Compare
Fixed leak using try-with-resources. However, changed the method to return a
List
and do thecollect
operation inside the method to avoid try-with-resources closing the stream before its last use. This ensures the resources to be cleaned up. Fixes #1098