HttpClient crawling results in memory leak

前端 未结 4 1280
Happy的楠姐
Happy的楠姐 2020-12-24 07:32

I am working on a WebCrawler implementation but am facing a strange memory leak in ASP.NET Web API\'s HttpClient.

So the cut down version is here:


[UP

4条回答
  •  时光取名叫无心
    2020-12-24 08:06

    The default HttpClient leaks when you use it as a short-lived object and create new HttpClients per request.

    Here is a reproduction of this behavior.

    As a workaround, I was able to keep using HttpClient as a short-lived object by using the following Nuget package instead of the built-in System.Net.Http assembly: https://www.nuget.org/packages/HttpClient

    Not sure what the origin of this package is, however, as soon as I referenced it the memory leak disappeared. Make sure that you remove the reference to the built-in .NET System.Net.Http library and use the Nuget package instead.

提交回复
热议问题