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

为君一笑 提交于 2019-12-22 10:45:00

问题


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) 

回答1:


How do you initialize your RequestQueue? I suspect that you are creating RequestQueues 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.




回答2:


I used static queue instead of creating new queue in my Record class

I changed code from

public class Record {

    private RequestQueue RecordSyncQueue = Volley.newRequestQueue(ImonaAndroidApp.app);

}

to

public class Record {

    private static RequestQueue RecordSyncQueue = Volley.newRequestQueue(ImonaAndroidApp.app);

}


来源:https://stackoverflow.com/questions/21475129/volley-give-me-out-of-memory-exception-after-i-make-a-lot-of-request-with-big-am

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!