Hello all,
I found memory leak when I sent files to API using IFormFile interface.
With version 2.1 everything is ok.
Simple example:
Content-type: multipart/form-data
[ApiController]
public class FormController : ControllerBase
{
[HttpPost]
[Route("[controller]/Insert")]
public async Task<IActionResult> Insert([FromForm] Form form)
{
return Ok();
}
}
public class Form
{
public string Name { get; set; }
public IFormFile File { get; set; }
public ICollection<DynamicInput> Inputs { get;set; }
}
public class DynamicInput
{
public string Name { get; set; }
public IFormFile File { get; set; }
}

@kameleon71 Can you provide a full repro? (Client included).
Here you are: https://github.com/kameleon71/asp.net.core.2.2.memory.leak
This example is based on template asp.net.core web app in VS2017 (angular client)
Just run, click fetch data and watch memory usage ;)
@davidfowl any status on this; we have this issue too...
@davidfowl
This seams to be caused by the following method being called when an array of IFormFiles has to be parsed by the ModelBinder. It does a loop with an upper range of int.MaxValue
cc @pranavkm
@dougbu is this the same class of issue as https://github.com/aspnet/AspNetCore/issues/7052?
We upgraded to .NET Core 2.2 and memory climbed to 100% over a few days easily. I'm not sure of the cause yet but have taken a few memory dumps but unable to analyze right now, will hopefully understand more soon.
This issue is a duplicate of #4802. The #6793 fix will correct both issues, in 3.0 Preview 3 we hope.
(@pranavkm #7052 relates to binders that succeed unconditionally (and repeatedly) in the same request. The FormFileModelBinder isn't in that category.)
I have also experienced this problem and for those who doesn't want to revert back to .Net Core 2.1 I suggest using Non-Sequential Indices like described in this article: https://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx/.
In my views I create a string guid index and then use it to bind a model to a list:
@{var fileGuid = Guid.NewGuid().ToString();}
<input type="hidden" name="DocumentsForm.TypedFileList.Index" value="@fileGuid" />
<input type="file" name="DocumentsForm.TypedFileList[@fileGuid].File" class="inputfile" />
Most helpful comment
Here you are: https://github.com/kameleon71/asp.net.core.2.2.memory.leak
This example is based on template asp.net.core web app in VS2017 (angular client)
Just run, click fetch data and watch memory usage ;)