Android Volley.newRequestQueue正在导致OutOfMemoryError

Android Volley.newRequestQueue正在导致OutOfMemoryError,android,caching,out-of-memory,android-volley,Android,Caching,Out Of Memory,Android Volley,我正在使用截击设置图像url。我的代码在以下位置崩溃: mrq=Volley.newRequestQueue(this); Log cat表示豁免位于:com.android.volley.toolbox.DiskBasedCache.streamToBytes 如果我注释掉代码,程序不会崩溃 我试过几次重启我的手机,因为在我的研究中,我发现这对一些有这个问题的人是有效的 为什么创建RequestQueue要使用这么多内存 如何防止OutOfMemoryError发生 我需要清空缓存吗 感谢您

我正在使用截击设置图像url。我的代码在以下位置崩溃:

mrq=Volley.newRequestQueue(this);
Log cat表示豁免位于:
com.android.volley.toolbox.DiskBasedCache.streamToBytes

如果我注释掉代码,程序不会崩溃

我试过几次重启我的手机,因为在我的研究中,我发现这对一些有这个问题的人是有效的

为什么创建RequestQueue要使用这么多内存

如何防止OutOfMemoryError发生

我需要清空缓存吗


感谢您的帮助,并花时间阅读此文章。

如何初始化您的请求队列?我怀疑您正在为每个活动创建RequestQueues。因此,请在应用程序中启动它

    public class ApplicationController extends Application {
        private static ApplicationController sInstance;
        private RequestQueue mRequestQueue;

        @Override
    public void onCreate() {
        super.onCreate();

        // initialize the singleton
        sInstance = this;
    }

 public static synchronized ApplicationController getInstance() {
        return sInstance;
    }



        public RequestQueue getRequestQueue() {
                // lazy initialize the request queue, the queue instance will be
                // created when it is accessed for the first time
                if (mRequestQueue == null) {
                    mRequestQueue = Volley.newRequestQueue(getApplicationContext());
                }

                return mRequestQueue;
            }


    //your code


    }
并从活动中获取请求队列作为

mrq = ApplicationController.getInstance().getRequestQueue();

如何初始化RequestQueue?我怀疑您正在为每个活动创建RequestQueues。因此,请在应用程序中启动它

    public class ApplicationController extends Application {
        private static ApplicationController sInstance;
        private RequestQueue mRequestQueue;

        @Override
    public void onCreate() {
        super.onCreate();

        // initialize the singleton
        sInstance = this;
    }

 public static synchronized ApplicationController getInstance() {
        return sInstance;
    }



        public RequestQueue getRequestQueue() {
                // lazy initialize the request queue, the queue instance will be
                // created when it is accessed for the first time
                if (mRequestQueue == null) {
                    mRequestQueue = Volley.newRequestQueue(getApplicationContext());
                }

                return mRequestQueue;
            }


    //your code


    }
并从活动中获取请求队列作为

mrq = ApplicationController.getInstance().getRequestQueue();

一个关键概念是,必须使用应用程序上下文而不是活动上下文实例化RequestQueue。这确保了RequestQueue将在应用程序的整个生命周期内持续,而不是每次重新创建活动时都重新创建。一个关键概念是,RequestQueue必须使用应用程序上下文而不是活动上下文实例化。这确保了RequestQueue将在应用程序的整个生命周期内持续,而不是每次重新创建活动时都重新创建它

您是否在活动中启动mrq,即RequestQueue?我是<代码>私有请求队列mrq您是否在活动中启动mrq即RequestQueue?我是<代码>私有请求队列mrq