Volley give me Out of memory exception after I make a lot of request with big amount of data

android, android-volley, out-of-memory

Solution

How do you initialize your `RequestQueue`? I suspect that you are creating `RequestQueue`s for each tab. If that's the case, change your program to use one common instance of `RequestQueue` from all the tabs. You need to initialize and retain it in your activity and add requests to it from each tab.

Problem

I have a Page Viewer and inside every page I have list View , this list view will have 10 records using a web service , so the page viewer use three calls of the web service to populate three pages (the current , the left and the right page) but after I make a lot of swipes I am getting this exception : ``` java.lang.OutOfMemoryError: pthread_create (stack size 16384 bytes) failed: Try again at java.lang.VMThread.create(Native Method) at java.lang.Thread.start(Thread.java:1029) at com.android.volley.RequestQueue.start(RequestQueue.java:142) at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:66) at com.android.volley.toolbox.Volley.newRequestQueue(Volley.java:78) at com.imona.android.entities.Record.<init>(Record.java:57) at com.imona.android.webservices.OperationalDataRest$1.onResponse(OperationalDataRest.java:109) at com.imona.android.webservices.OperationalDataRest$1.onResponse(OperationalDataRest.java:85) at com.android.volley.toolbox.JsonRequest.deliverResponse(JsonRequest.java:65) at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5017) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main(Native Method) ```

Original source