admin管理员组

文章数量:1310108

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()
responseworkResponse.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?

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()
responseworkResponse.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?

Share Improve this question asked Feb 2 at 6:33 SMBiggsSMBiggs 11.7k6 gold badges74 silver badges89 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

From the Response docs:

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

本文标签: In OkHttp what is the difference between responseclose() and responsebodyclose()Stack Overflow