我从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)`
答案 0 :(得分:0)
我发现这个解决方案似乎就是每个请求都在我的HTTP模块中重新创建请求队列。为了避免这种情况,我在模块中使用了以下单例类
`public class RequestQueSingleton { private static RequestQueSingleton sSoleInstance; private static 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;
}}`