Anonymous Listener of volley request causing memory leak

后端 未结 4 1865
别跟我提以往
别跟我提以往 2021-01-05 07:14

I am using volley library for making web-services call. I made a general class for making all web services call and making service call from there and made anonymous listene

4条回答
  •  梦毁少年i
    2021-01-05 07:56

    I had a similar problem detected with LeakCanary where Volley's mListener was referencing my response listener, and my listener was referencing an ImageView, so it could update it with the downloaded image.

    I made my response listener an inner class within the activity ..

    private class MyVolleyResponseListener  implements com.android.volley.Response.Listener  {
    
            @Override
            public void onResponse(Bitmap bitmap) {
                thumbNailView.setImageBitmap(bitmap);
            }
    }
    

    .. and stopped and started the volley request queue inside onDestroy() in the activity ..

    requestQueue.stop();
    requestQueue.start();
    

    This has fixed the leak.

提交回复
热议问题