Is there any chance that fileStream object will likely be destroyed before its call to the Close method as below?
No.
But you should never write code like that. You should always wrap IDisposable resources in using
statements to ensure that they will be disposed even if an exception is thrown and that you won't be leaking handles.
using (FileStream fileStream = new FileStream(xxx))
using (StreamReader txtReader = new StreamReader(fileStream))
{
curLog = txtReader.ReadToEnd();
}
But for the purpose of this specific example you could simply use the ReadAllText
method.
string curLog = File.ReadAllText(xxx);