-
Notifications
You must be signed in to change notification settings - Fork 640
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
Dispose of some disposables, #265, #615 #1074
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.
Thanks for the PR.
I agree that keeping CA2000 on would not be a great idea. That being said, some of these had real underlying issues, but others also inadvertently cause Dispose()
to be called multiple times on the underlying stream. What is your estimate on how thorough this review is?
IDisposable
is a leaky abstraction, so when it is implemented in a base class all of the subclasses automatically inherit it even if they don't require it. I think the Lucene team is pretty thorough about declaring most of them properly, but there are some exceptions to this. It would be good to catch those exceptions before the release, if possible.
Disposes of some IDisposable objects that are not properly cleaned up.
Fixes #615
Partial #265
Description
This adds
using
statements to clean up some disposable objects where it's possible to do so, after a review of our codebase with CA2000 code analysis warnings on, where the objects were determined to not "leak" via fields, return values, or the like. This also fixes two FileStream leaks in demo code, #615.Note that CA2000 is way too noisy to leave on, as there are literally hundreds of "violations" that would make our code a mess with
#pragma
suppressions. The Java upstream code is perhaps a little loose with keeping track of ICloseable lifetimes, but we have to match that in most cases. The cases fixed here were just ones where the object lifetime did not escape the method and it was safe to do so.