Interesting idea. I had not thought of that. OTOH, I just read on the Web that it is not considered good practice to rely on finalize for cleanup, since it might be called at unpredictable times (possibly never). So the documentation would not change: one would always recommend users to close the stream as soon as possible.

So should we close the stream on finalize as a final (literally) safety measure? A problem might be that of ownership and object lifetime. If finalize() of the dump object will close the stream, then the stream might become unusable as soon as the there is no remaining reference to the dump object. So in principle, any code that requests a stream would need to keep an own reference to the dump while using the stream to be completely safe (and if it would not do this, then there could be random problems that are triggered by the unpredictable activity of the garbage collection). Probably a rather theoretical issue, but nevertheless.