Out of memory error android due to fragmentation after 20+days

北战南征 提交于 2020-08-08 06:19:10

问题


I made a application that runs on a coffee machine.
After 20+ days (can be 60+ days depending on use) an OutOfMemoryError occurs:

    java.lang.OutOfMemoryError: Failed to allocate a 604 byte allocation with 16777216 free bytes and 319MB until OOM; failed due to fragmentation (required continguous free 65536 bytes for a new buffer where largest contiguous free 53248 bytes)

My question is:
Is there a way to run a defragmentation on memory android application programmatically?

The time it takes should not be a issue because machine goes into standby or eco mode.
And what I see is that there is more than enough memory available.


回答1:


Is there a way to run a defragmentation on memory android application programmatically?

No. On Android 5.0-7.1, the best thing that you can do is get out of the foreground, as ART's garbage collector will compact memory only when your app is in the background. On Android 8.0+, ART's garbage collector will compact memory even while you are in the foreground.

Beyond that, aim to start a fresh process once per week or something, so you get a fresh heap.



来源:https://stackoverflow.com/questions/50624338/out-of-memory-error-android-due-to-fragmentation-after-20days

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