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

TwitchAPI should implement IDisposable / IAsyncDisposable to clean up HttpClient #368

Open
danbopes opened this issue Aug 7, 2023 · 1 comment

Comments

@danbopes
Copy link

danbopes commented Aug 7, 2023

As noted in the title. The TwitchAPI creates a handler http, which should be disposed of for short lived TwitchAPI uses.

@Omsad
Copy link

Omsad commented Aug 18, 2023

As far as I'm aware you should never dispose of an HttpClient explicitly as doing so will lead to a memory leak. See https://stackoverflow.com/questions/27732546/httpclienthandler-httpclient-memory-leak .

So if you were to make the TwitchAPI disposable, you would presumable want to clean up the HttpClient it uses internally which would then cause memory issues.

What should be changed instead is that an IHttpClientFactory should be used to create an IHttpClient instance, that way each TwitchAPI would get the same instance of the HttpClient and it would be re-used without issue.

This is what I do in my own program, e.g. I explicitly create a TwitchHttpClient for the TwitchAPI and the HttpClient the TwitchHttpClient receives is the same one every time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants