Does IFormFile.OpenReadStream() need to be disposed?

Viewed 1684
1 Answers

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.

Related