Code Analysis rule not triggered for a likely memory leak

Viewed 39

The type HttpResponseMessage is an IDisposable: public class HttpResponseMessage : IDisposable

I intentionally enabled CA2000 in my Solution Explorer to detect places in my code where I forgot to explicitly dispose of things.

Given this simple method below, I was expecting the Code Analysis engine to generate a CA2000 response, but it did not. Shouldn't response be disposed?

private async Task<T> GetAsync<T>(string url)
{
    // GetSomeHttpResponseAsync is a custom extension method if that helps.
    HttpResponseMessage response = await myHttpClient.GetSomeHttpResponseAsync(url);
    return await DeserializeJsonAndHandleClientError<T>(response);
}
0 Answers
Related