Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion aspnetcore/blazor/call-web-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,24 @@ The solution includes a demonstration of obtaining weather data securely via an

## Disposal of `HttpRequestMessage`, `HttpResponseMessage`, and `HttpClient`

An <xref:System.Net.Http.HttpRequestMessage> without a body doesn't require explicit disposal with a [`using` declaration (C# 8 or later)](/dotnet/csharp/language-reference/proposals/csharp-8.0/using) or a [`using` block (all C# releases)](/dotnet/csharp/language-reference/keywords/using), but we recommend disposing with every use for the following reasons:
An <xref:System.Net.Http.HttpRequestMessage> without a body doesn't require explicit disposal. However, you can dispose of it with either of the following patterns:

* `using` declaration (C# 8 or later):

```csharp
using var request = new HttpRequestMessage(...);
```

* [`using` block (all C# releases)](/dotnet/csharp/language-reference/keywords/using):

```csharp
using (var request = new HttpRequestMessage(...))
{
...
}
```

We recommend disposing of every <xref:System.Net.Http.HttpRequestMessage> with every use for the following reasons:

* To gain a performance improvement by avoiding finalizers.
* It hardens the code for the future in case a request body is ever added to an <xref:System.Net.Http.HttpRequestMessage> that didn't initially have one.
Expand Down