最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论