Skip to main content
Post Reopened by Gerhard, yu yang Jian, Yury Schkatula
Post Closed as "Needs more focus" by TylerH, General Grievance, desertnaut
Thread title is highly misleading. It focuses on performance issues, not whether you should dispose client or not. You should, always, to release resources.
Link
Alexander
  • 4.2k
  • 1
  • 26
  • 38

Do HttpClient and HttpClientHandler have to be disposed between requests?

Correct spelling (Superflous -> Superfluous); add missing words (about)
Source Link

The second paragraph is superfloussuperfluous to this question, which is not concerned about how many times you can use an HttpClient instance, but about if it is necessary to dispose it after you no longer need it.

The second paragraph is superflous to this question, which is not concerned about how many times you can use an HttpClient instance, but if it necessary to dispose it after you no longer need it.

The second paragraph is superfluous to this question, which is not concerned about how many times you can use an HttpClient instance, but about if it is necessary to dispose it after you no longer need it.

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

This answerThis answer uses this pattern:

  1. Is it necessary, given the current implementation (.NET Framework 4.5), to call Dispose() on HttpClient and HttpClientHandler instances? Clarification: by "necessary" I mean if there are any negative consequences for not disposing, such as resource leakage or data corruption risks.

  2. If it's not necessary, would it be a "good practice" anyway, since they implement IDisposable?

  3. If it's necessary (or recommended), is this codethis code mentioned above implementing it safely (for .NET Framework 4.5)?

  4. If these classes don't require calling Dispose(), why were they implemented as IDisposable?

  5. If they require, or if it's a recommended practice, are the Microsoft examples misleading or unsafe?

This answer uses this pattern:

  1. Is it necessary, given the current implementation (.NET Framework 4.5), to call Dispose() on HttpClient and HttpClientHandler instances? Clarification: by "necessary" I mean if there are any negative consequences for not disposing, such as resource leakage or data corruption risks.

  2. If it's not necessary, would it be a "good practice" anyway, since they implement IDisposable?

  3. If it's necessary (or recommended), is this code mentioned above implementing it safely (for .NET Framework 4.5)?

  4. If these classes don't require calling Dispose(), why were they implemented as IDisposable?

  5. If they require, or if it's a recommended practice, are the Microsoft examples misleading or unsafe?

This answer uses this pattern:

  1. Is it necessary, given the current implementation (.NET Framework 4.5), to call Dispose() on HttpClient and HttpClientHandler instances? Clarification: by "necessary" I mean if there are any negative consequences for not disposing, such as resource leakage or data corruption risks.

  2. If it's not necessary, would it be a "good practice" anyway, since they implement IDisposable?

  3. If it's necessary (or recommended), is this code mentioned above implementing it safely (for .NET Framework 4.5)?

  4. If these classes don't require calling Dispose(), why were they implemented as IDisposable?

  5. If they require, or if it's a recommended practice, are the Microsoft examples misleading or unsafe?

clarification
Source Link
Fernando Correia
  • 22.5k
  • 14
  • 87
  • 119
Loading
nitpicking
Source Link
Fernando Correia
  • 22.5k
  • 14
  • 87
  • 119
Loading
additional example
Source Link
Fernando Correia
  • 22.5k
  • 14
  • 87
  • 119
Loading
Source Link
Fernando Correia
  • 22.5k
  • 14
  • 87
  • 119
Loading