当我对大量数据进行大量请求后,Volley给我“内存不足"异常 [英] Volley give me Out of memory exception after I make a lot of request with big amount of data

查看:200
本文介绍了当我对大量数据进行大量请求后,Volley给我“内存不足"异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面查看器,每个页面内都有列表视图,该列表视图将使用Web服务包含10条记录,因此页面查看器使用Web服务的三个调用来填充三个页面(当前,左侧和正确的页面),但是在我多次滑动后,出现了这个异常:

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) 

推荐答案

如何初始化RequestQueue?我怀疑您正在为每个选项卡创建RequestQueue.在这种情况下,请更改程序以在所有选项卡中使用RequestQueue的一个常见实例.您需要对其进行初始化并将其保留在活动中,并从每个选项卡向其添加请求.

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.

这篇关于当我对大量数据进行大量请求后,Volley给我“内存不足"异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆