繁体   English   中英

Volley Out of Memory问题V1.1.0

[英]Volley Out Of Memory issue V1.1.0

我收到了Volley的“内存不足”问题。 目前,我的请求对象创建是这样的

if (reQuestQue == null) {
    reQuestQue = Volley.newRequestQueue(mContext);
}
reQuestQue.add(mGsonRequest);`

我收到此异常:

Fatal Exception: java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed:
Try again
           at java.lang.Thread.nativeCreate(Thread.java)
           at java.lang.Thread.start(Thread.java:1063)
           at com.android.volley.RequestQueue.start(RequestQueue.java:135)
           at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:91)
           at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:67)
           at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:102)`

我发现此问题的解决方案似乎是在每个请求的HTTP模块中重新创建请求队列。 为了避免这种情况,我在模块中使用了以下单例类

公共类RequestQueSingleton {私有静态RequestQueSingleton sSoleInstance; 私有静态RequestQueue reQuestQue;

private RequestQueSingleton(){}  //private constructor.

public static RequestQueSingleton getInstance(Context context){
    if (sSoleInstance == null){ //if there is no instance available... create new one
        sSoleInstance = new RequestQueSingleton();
        reQuestQue = Volley.newRequestQueue(context);
    }

    return sSoleInstance;
}


public  synchronized RequestQueue getInstance() {
    Log.d("Request Que Obj",reQuestQue.hashCode()+"");
    return reQuestQue;
}}`

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM