I believe all of these problems would go away if programmers would follow the rule that the same module that opens (or otherwise creates) a stream is responsible for closing (or otherwise disposing of) it. This seems eminently simple and sensible, and has worked well for us for many years.