Home >Backend Development >C++ >Should I Dispose of HttpClient and HttpClientHandler in .NET?
and in the .NET Framework 4.5 inherit the interface.
Do they need to release them? System.Net.Http.HttpClient
System.Net.Http.HttpClientHandler
Although and IDisposable
have been implemented, they do not need to be released after each request. Their design purpose is to use it in multiple requests in multiple long -term use to keep setting and prevent redundant request configuration.
Best practice or misleading example? Although the documentation is recommended to use the
statement for the release object, the example of the official Microsoft has not demonstrated its release. This is not necessarily misleading or unsafe, because experts have clarified and released. HttpClient
HttpClientHandler
So why do you realize IDISPOSABLE? IDisposable
provides options to release resources and handle any specific cleaning scheme. However, the release of the main purpose of HTTP request is not a recommended approach. Conclusion
using
In short, in the .NET Framework 4.5, it was unnecessary to release HttpClient
and
The above is the detailed content of Should I Dispose of HttpClient and HttpClientHandler in .NET?. For more information, please follow other related articles on the PHP Chinese website!