The questions is if the content is disposed properly in all scenarios?
FYI, httpClient is an instance injected using DI and AddHttpClient() in Startup.cs, the project is a regular REST API .NET 5.
I always use the 3th approach since HttpClient instance is supposed to dispose HttpContent when HttpClient is disposed.
But what about the other ways? Just out of curiosity how it works underneath.
Might 2nd scenario cause memory leaks?
Or maybe the 1st approach and use of using is not needed here since parent's disposal (httpclient) takes care of everything implicitly, anyway?
What do you think?
What I have tried:
1.
var json = JsonConvert.SerializeObject(myObj);
using var httpContent = new StringContent(json);
var response = await _httpClient.PostAsync("path", httpContent);
2.
var json = JsonConvert.SerializeObject(myObj);
var httpContent = new StringContent(json);
var response = await _httpClient.PostAsync("path", httpContent);
3.
var json = JsonConvert.SerializeObject(myObj);
var response = await _httpClient.PostAsync("path", new StringContent(json));