okhttp icon indicating copy to clipboard operation
okhttp copied to clipboard

got leak memory from okhttp3.Callback

Open dndxxiangyu opened this issue 9 years ago • 1 comments

When I use such code in Activity: Call call = client.newCall(request); call.enqueue(new Callback() { @Override public void onFailure(Call call, IOException e) { } @Override public void onResponse(Call call, Response response) throws IOException { try { Thread.sleep(60 * 1000); } catch (InterruptedException e) { e.printStackTrace(); } } }); now you can see I use a Anonymous Inner Class for Callback. Everyone knows the object of Callback will have a reference from the Outter Class of Activity. So when I go to this Activity and press the Button to have a network, and then press back key quickly, you will see the leak memory with the tool of leakcanary. How can I avoid it.(I know a method of to create a static Callback object, but it is complex).

dndxxiangyu avatar Jun 14 '17 06:06 dndxxiangyu

This issue tracker is for feature requests and bug reports only. Please try StackOverflow.

swankjesse avatar Jun 14 '17 08:06 swankjesse