提问者:小点点

Volley内存不足问题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)`

共1个答案

匿名用户

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

'public class Request estQueSingleton{私有静态Request estQueSingleton sSoleInstance;私有静态Request estQueue 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;
}}`