Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 265
Steven Goossens Avatar asked Oct 19 '25 14:10

Steven Goossens


1 Answers

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.

like image 75
CommonsWare Avatar answered Oct 21 '25 04:10

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!