Note that there are some explanatory texts on larger screens.

plurals
  1. POUnderstanding Streams and their lifetime (Flush, Dispose, Close)
    primarykey
    data
    text
    <p>Note: I've read the following two questions already:</p> <p><a href="https://stackoverflow.com/questions/507747/can-you-explain-the-concept-of-streams">Can you explain the concept of streams?</a></p> <p><a href="https://stackoverflow.com/questions/1404303/c-using-streams">C# using streams</a></p> <p>I'm coding in C#</p> <ol> <li>In almost all code samples that use streams, .Dispose(), .Flush(), .Close() are almost always called. <ul> <li>In the concept of a stream, what does accomplish?</li> <li>If I don't dispose a stream that I stored in a variable, is my application leaking somewhere?</li> <li>Why do I need to call any of these functions? I've seen code samples that don't do this and still get the job done (without an <strong>apparent</strong> breakage)</li> </ul></li> </ol> <p>I'm currently building a class in my application that contains a primary method (lets call it <code>GetStream()</code>) that returns a stream via <code>myWebRequest.GetResponse().GetResponseStream()</code></p> <p>The primary method <code>GetStream()</code> returns a <code>Stream</code> object that can be used for any operation that requires a stream (StreamReader, Bitmap() etc.).</p> <p>Is there a way to have the stream Disposed of automatically after its last use (garbage collected?) without forcing anyone that calls <code>.GetStream()</code> to manually dispose of it?</p> <p>As you can probably tell, my questions are vague and general. My understanding of streams is not solid, so any links to helpful articles that offer a more in-depth look at streams than a SO question can offer would be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload