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?