Android OutOfMemoryError - Loading JSON File

Posted by jeremynealbrown on Stack Overflow See other posts from Stack Overflow or by jeremynealbrown
Published on 2010-05-22T01:41:27Z Indexed on 2010/05/22 1:50 UTC
Read the original article Hit count: 362

Filed under:
|
|
|
|

The app I am working on needs to read a JSON file that may be anywhere from 1.5 to 3 MB in size. It seems to have no problem opening the file and converting the data to a string, but when it attempts to convert the string to a JSONArray, OutOfMemoryErrors are thrown. The exceptions look something like this:

E/dalvikvm-heap( 5307): Out of memory on a 280-byte allocation.
W/dalvikvm( 5307): Exception thrown (Ljava/lang/OutOfMemoryError;) while throwing internal exception (Ljava/lang/OutOfMemoryError;)

One strange thing about this is that the crash only occurs every 2nd or 3rd time the app is run, leaving me to believe that the memory consumed by the app is not being garbage collected each time the app closes.

Any insight into how I might get around this issue would be greatly appreciated. I am open to the idea of loading the file in chunks, but I'm not quite sure what the best approach is for such a task.

Thank you

© Stack Overflow or respective owner

Related posts about android

Related posts about java