The Wayback Machine - https://web.archive.org/web/20200515055746/https://github.com/square/retrofit/issues/2950
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

Question: Do I need to close ResponseBody? #2950

Open
Malachiasz opened this issue Nov 12, 2018 · 2 comments
Open

Question: Do I need to close ResponseBody? #2950

Malachiasz opened this issue Nov 12, 2018 · 2 comments
Labels

Comments

@Malachiasz
Copy link

@Malachiasz Malachiasz commented Nov 12, 2018

When Retrofit2 returns okhttp3.ResponseBody then it has to be closed in order to avoid memory leaks, right? It's something what I have just noticed in our code and am not sure.

@GET("accountId")
@WorkerThread
Call<ResponseBody> getUserData(@Header(NetworkConstants.Header.AUTHORIZATION) String accessToken);

...
Response<ResponseBody> response = interface.getUserData();
// do something with response
response.body().close()

https://stackoverflow.com/questions/53265862/do-i-need-to-close-response

@JakeWharton
Copy link
Collaborator

@JakeWharton JakeWharton commented Nov 12, 2018

Only if you have @Streaming on the method. Otherwise it's fully buffered. We should document it as such.

@MonikaJethani
Copy link

@MonikaJethani MonikaJethani commented May 21, 2019

@JakeWharton Is this done? Can I work on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants
You can’t perform that action at this time.