HttpClientHandler / HttpClient Memory Leak

后端 未结 4 1416
逝去的感伤
逝去的感伤 2020-12-03 01:24

I have anywhere from 10-150 long living class objects that call methods performing simple HTTPS API calls using HttpClient. Example of a PUT call:



        
4条回答
  •  醉梦人生
    2020-12-03 02:12

    As Matt Clark mentioned, the default HttpClient leaks when you use it as a short-lived object and create new HttpClients per request.

    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.

提交回复
热议问题