5

I have received the following strange crash report for my Android App from Google Play (note the amount of allocation vs the free space available) -

java.lang.OutOfMemoryError: Failed to allocate a 16396 byte allocation with 5746272 free bytes and 111MB until OOM
    at com.android.internal.util.FastXmlSerializer.<init>(FastXmlSerializer.java:55)
    at com.android.internal.util.XmlUtils.writeMapXml(XmlUtils.java:183)
    at android.app.SharedPreferencesImpl.writeToFile(SharedPreferencesImpl.java:597)
    at android.app.SharedPreferencesImpl.access$800(SharedPreferencesImpl.java:51)
    at android.app.SharedPreferencesImpl$2.run(SharedPreferencesImpl.java:512)
    at android.app.SharedPreferencesImpl.enqueueDiskWrite(SharedPreferencesImpl.java:533)
    at android.app.SharedPreferencesImpl.access$100(SharedPreferencesImpl.java:51)
    at android.app.SharedPreferencesImpl$EditorImpl.commit(SharedPreferencesImpl.java:455)
    at com.headuck.headuckblocker.bj.a(Unknown Source)
    at com.headuck.headuckblocker.UpdateService.e(Unknown Source)
    at com.headuck.headuckblocker.UpdateService.a(Unknown Source)
    at x.a.onHandleIntent(Unknown Source)
    at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:65)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:145)
    at android.os.HandlerThread.run(HandlerThread.java:61)

I am aware of a number of OutOfMemoryError questions on SO, but it seems none of them is caused by byte allocation much smaller than the free space available.

The user was using a Galaxy S5 on Android 5.0, and reported that such crashes occur while playing games (and which games doesn't matter) - which I take that this recurs whenever he/she is using another memory intensive app in foreground and the background service of my App is scheduled to run. Being a Google Play report, I have no other means of obtaining more details.

My question is, what possibly could cause this to happen, and any measures that an app could take to avoid it?

Some background (in case this is relevant): the above crash is from a periodically scheduled background service of my App, which does not involve any UI / bitmap. All it does is downloading data from server and updating database / status. It ran without any problem in 5 year old machines with much fewer RAM, and should be very light on memory by the standards of modern Android phones. The above instance of error happens at a point after the database update and the service is writing updated status to the shared preference.

Edit: just read OutOfMemoryError in android on allocation 4Mb when 10Mb is free which was linked to this question after posting, but it just appears quite improbable that the free space available can be so fragmented in this case? Is there any other possible cause?

Community
  • 1
  • 1
headuck
  • 2,763
  • 16
  • 19

2 Answers2

0

if you are using Android Studio then add "LargeHeap=true" in your manifest file.

Like this;

android:largeHeap="true"

Bhoomika
  • 105
  • 1
  • 7
  • Thanks but the problem is not that my service is particularly memory hungry, so that is definitely an over-kill, and is not a recommended practice http://stackoverflow.com/questions/27396892/androidlargeheap-true-in-mainifast-advantages – headuck Jan 05 '16 at 04:52
  • i don't think so it is good idea to add largeheap to true . and according the stacktrace there is no bitmap operation are done for causing oom.http://stackoverflow.com/questions/27396892/androidlargeheap-true-in-mainifast-advantages – mcd Jan 05 '16 at 04:53
0

I've faced similar issue. This is what I did to solve it

  1. Create a new folder drawable-nodpi in your res/ folder
  2. Move all "images" in /drawable folder to /drawable-nodpi folder

Hope this helps somebody :)

  • Thanks, perhaps useful to others but in my particular case it is a background process without using any drawable, so this is not applicable to me. – headuck Feb 01 '16 at 15:57