I have a new project with existing code. And I saw that in one method was used a stream without 'using' statement:
private FileInfoRequest ParseFileInfoRequest(Stream body)
{
try
{
var sr = new StreamReader(body, Encoding.UTF8);
return JsonConvert.DeserializeObject<FileInfoRequest>(sr.ReadToEnd());
}
catch (Exception ex)
{
_log.Error("Could not parse FileInfoRequest", ex);
throw Thrower.GetThrowError(HttpStatusCode.BadRequest,
_localization.Api().BadRequestBody,
UiMessageKey.ApiBadRequest);
}
}
Question is: will this stream clear by GC or I need to write something like:
using(sr)
{
return JsonConvert.DeserializeObject<FileInfoRequest>(sr.ReadToEnd());
}