Should IFormFile.OpenReadStream() be called inside a using block so it's properly disposed of? Or will it be disposed of by the IFormFile after the http request finishes processing?
Should IFormFile.OpenReadStream() be called inside a using block so it's properly disposed of? Or will it be disposed of by the IFormFile after the http request finishes processing?
The default implementation of FormFile creates a new ReferenceReadStream every time OpenReadStream() is called:
https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/Http/Http/src/FormFile.cs#L81
ReferenceReadStream does not contain any unmanaged resources. Calling Dispose on it is essentially a no-op.
https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/Http/Http/src/Internal/ReferenceReadStream.cs#L14
With that in mind, IFormFile.OpenReadStream() doesn't need to be disposed. But disposing it also doesn't hurt anything.