Although it will be collected by the garbage collector eventually, it's a rather bad practice to leave it there uncollected.
You can ensure that it's cleaned up by wrapping it in a using
:
using (var br = new BinaryReader(MyStream))
{
return DoMoreThings(br);
}
The only drawback here is that the using
means that it will call br.Dispose
, which among other things will close the underlying stream: MyStream
in this case. You can prevent that by calling the overloaded constructor, telling it to leave the stream open:
using (var br = new BinaryReader(MyStream, Encoding.UTF8, true))
Replace the Encoding.UTF8
with whatever encoding matches the strings in your file. Encoding.UTF8
is the default used by the constructor that doesn't take an Encoding parameter.