Fixed undisposed writers in CSV saving #1248
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This fixes a small bug where the CSV Save functions don't dispose the writers they use, and therefore leave stream flushing and potentially file handles open until garbage collection cleans up the writers. I've simply changed the
let writer
s touse writers
to ensure they are disposed correctly.One point that's worth some discussion: for the
Save(stream : Stream ...
overload, I've made it so that the save does not close the underlying stream. Instead, the writer flushes into it, but leaves it open. I chose to do this because I'm of the opinion that if I give a stream to something, I (the caller) own it and I will close and dispose it when I'm done with it. I don't expectSave
to close and dispose it for me.However this is not the default behaviour when you pass a Stream to a Writer, hence why I'm using a more complicated overload.