Volley OutOfMemoryError

爱⌒轻易说出口 提交于 2019-12-07 10:59:05

问题


We're getting an OutOfMemory error inside the Volley library while parsing the network response. This occurs with a large responses on crappy phones. Can this be avoided? Is there any way to tell Volley to parse the response in batches maybe?

Here's the exception:

07-18 14:33:41.449    6130-6154/com.tinder E/AndroidRuntime: FATAL EXCEPTION: Thread-22
    java.lang.OutOfMemoryError
    at java.lang.String.<init>(String.java:325)
    at java.lang.String.<init>(String.java:276)
    at com.android.volley.toolbox.JsonObjectRequest.parseNetworkResponse(JsonObjectRequest.java:66)
    at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:116)

This occurs on the Droid X (2.3.4).


回答1:


The only time I saw OutOfMemoryErrors in Volley was when I had an OS 2.3 specific memory leak in my code. If you can reliably reproduce this error (e.g. in an automated test with test data) then you should probably raise an issue in the Google Android forum.

In case it might help others, I copied the Volley source into my own Github repository and made a small change so that OutOfMemoryErrors are handled as VolleyErrors. This makes it slightly cleaner to log/handle low memory conditions.

Here's the specific commit:
https://github.com/daj/volley/commit/c9e28fceda34074dda3734561502a20a28167ca9




回答2:


So, in order to solve this, I switched to using a generic HttpConnection and JsonReader to parse the input stream. Hopefully, somebody will add to Volley and enable it to return a JsonReader ... maybe it will be me ... in my copious spare time ...



来源:https://stackoverflow.com/questions/17734789/volley-outofmemoryerror

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