SMBiggs
SMBiggs

Reputation: 11696

In OkHttp what is the difference between response.close() and response.body.close()?

I am working with OkHttp for my connections. To avoid memory leaks by closing responses. But the docs and none of the information I found explains which close to use.

Here are the difference close functions I've found

response.close()
response.body.close()
response.peekBody(Int).close()
response.cacheResponse.close()
response.networkResponse.close()

and there's probably more. But it seems like the big one is response.close() which is fundamentally different from the others. Do I need to close the whole thing or just the body to avoid memory leaks?

Upvotes: 0

Views: 40

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40623

From the Response docs:

This class implements Closeable. Closing it simply closes its response body. See ResponseBody for an explanation and examples.

Upvotes: 0

Related Questions