0

I am getting this Out of memory issue from Volley. Currently, my request object creation is like this

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

I am getting this exception:

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)`
ColdFire
  • 6,764
  • 6
  • 35
  • 51
Chinthaka Devinda
  • 997
  • 5
  • 16
  • 36

1 Answers1

1

I found the solution for this seems like I am recreating Request queue in my HTTP module per every request. To avoid that I used following singleton class in my module

`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;
}}`
Chinthaka Devinda
  • 997
  • 5
  • 16
  • 36