Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving doc for disposing response #409

Merged
merged 1 commit into from
Nov 29, 2023
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
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,40 @@ using FileStream fs = new FileStream($"I:\\i-am-a-binary-file.bin", FileMode.Cre
response.Content.ReadAsStream().CopyTo(fs);
```

### Disposing the response

> [!Important]
> You **MUST** dispose the response sent but any of the request. The device memory is limited and the response content will never be disposed if not asked. Depending on the devices, you may have only 16 possible requests before you'll get an out of memory.

Here is few right patterns to make sure you'll dispose properly the response content:

```csharp
using HttpResponseMessage response = client.Get(apiUrl);
// do whatever you want
// When the response object won't be used, it will be disposed
```

You can as well have an explicit using for a block:

```csharp
using HttpResponseMessage response = client.Get(apiUrl)
{
// do whatever you want
// when exiting the block, the response will be disposed
}
```

Or explicitly dispose the response:

```csharp
HttpResponseMessage response = client.Get(apiUrl);
// do whatever you want
// Dispose explicitly the content
response.Dispose();
```

In all cases, you **MUST** make ure you are disposing the response content.

### Debugging through a reverse proxy

When code is deployed to a MCU it might be desirable to let the device connect to your development machine running IIS Express.
Expand Down