What is the benefit from a user's point of view for closing a stream?
When running this code, it doesn't make visible difference to the user, whether you comment out response.Close();
or not.
Can anyone give me an example where not closing a stream/file handle etc would cause a noticeable problem to the user?
WebRequest request = WebRequest.Create("http://www.microsoft.com");
WebResponse response = request.GetResponse();
StreamReader responseStream = new StreamReader(response.GetResponseStream());
string responseText = responseStream.ReadToEnd();
Console.WriteLine(responseText); // Displays the HTML of the website
response.Close();
EDIT: Everyone is saying stuff like "it's good to dispose/close a stream so you release unmanaged resources". But can anyone provide me with an example showing how this can create a noticeable difference to the end user?