.NET Framework 4.5?
and HttpClient
need to be released for release? HttpClientHandler
and
A interface is implemented in the .NET Framework 4.5. System.Net.Http.HttpClient
The document of the statement is recommended to be released internally and instantiated. However, Microsoft's own examples often omit the calls of the HttpClientHandler
methods of these classes. IDisposable
using
Question 1: Is it necessary to explicitly release? Dispose()
and , it is not necessary to release
. Many experts including Darrel Miller (Microsoft Employees) confirmed this.
HttpClient
Question 2: Is release a good practice? HttpClientHandler
Although it is not needed, some people think that the release of object is still a good practice. However, it is necessary to consider performance effects.
Question 3: Is the example code safe? The code provided using the statement is usually considered safe in the .NET Framework 4.5. However, it should be noted that in the .NET 4.5, asynchronous and
statements have some restrictions.
IDisposable
Question 4: Why do these classes be implemented as IDISPOSABLE?
and are realized to facilitate the realization of the logic. However, the current implementation does not have any cleaning operation to be performed.
Question 5: Is Microsoft's example misleading? using
using
In view of the general consideration of
explicit release is not necessary, there is no call in Microsoft's examples that are not considered misleading, but just follow the reuse of multiple requests to reuse these. Recommended practice of class.
The above is the detailed content of Do I Need to Explicitly Dispose of HttpClient and HttpClientHandler?. For more information, please follow other related articles on the PHP Chinese website!