Confusion, and I agree that this is confusing, comes from a subtle but critical concept of stream ownership . In the MSDN examples, you can look at them as "Look, no Dispose , no Close , so shouldn't I?"
But the simple answer is that someone should be responsible for closing the stream. The API you are probably calling:
Application.GetResourceStream
returns StreamResourceInfo , which is a primitive container for the stream and URL. Obviously, StreamResourceInfo does not own the stream. Therefore, when you call Application.GetResourceStream , you now own the stream that is contained in this StreamResourceInfo , and if you have not done anything with it, you are responsible for closing it. The API Application transferred ownership of the flow from itself to us, returning it as a value to us.
Now the intricate part appears when you pass the stream to another object. Take the MSDN example:
Now in this example there is no Dispose and no Close . But there is a transfer of ownership of the stream from us (the caller) to the XamlReader instance. Flow is no longer our responsibility; we moved on to someone else. In fact, XamlReader calls Close when it is done with the stream. One riddle is solved.
The reason this is so problematic is because the concept of ownership is usually implied in the documentation, and we should "just understand it." We hope that only a revision of the concept of ownership and the fact that it is portable will simplify the comfortable not calling Close with the security that the new owner will have . And even if they do not, this is no longer our problem!
source share