com.squareup.okhttp.ConnectionPool pruneAndGetAllocationCount
when i ran my unit test, which contains a lot of, may be more than 10, requests, it came out a warning "A connection to http://localhost:8080/ was leaked. Did you forget to close a response body?"
why did this warning come out? how to solve it?
Are you closing the response body of all requests made in the test?
the sample https://github.com/square/okhttp/wiki/Recipes doesn't close response body neither.
normally i won't sumit so many requests at the same time, do i need to close response body all the time? just a little confused...
Which sample? Most call body().string() which closes it for you.
you mean if i call body().string(), no need to call body().close(), other situation it needs ?
after i call close for all response body except body().string(), no more warning.
Correct. We will document which methods on ResponseBody automatically close it.
If I use body().byteStream()do I need to close the connection explicitly as well?
Yes, per the javadoc, you'll need to close the body. Only bytes() and string() close it automatically. See https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/ResponseBody.java#L37
Just tried it but it seems if I close the stream after calling byteStream() I will then get an exception on processing the stream since it has already been closed.
I was confused ,,I got the warning when i used Retrofit ,,, I didn't have to do anything with the response body,how can I solve this ,,
I do have a custom interceptor ,, is it because of this ?
I also have the same problem using Retrofit when there are 2 concurrent http requests are under process. what could go wrong? I do have interceptors.
On a 64-bit API 25 Android emulator, the problem does not occur. But it occurs on the 32-bit emulator.