由于 20 多天后出现碎片,内存不足错误 android

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

我在咖啡机上制作了一个 运行s 的应用程序。
20 多天后(可能是 60 多天,具体取决于使用情况) 发生 OutOfMemoryError:

    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)

我的问题是:
有没有办法以编程方式 运行 对内存 android 应用程序进行碎片整理?

所需的时间应该不是问题,因为机器会进入待机或节能模式。
我看到的是可用内存绰绰有余。

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

没有。在 Android 5.0-7.1 上,您能做的最好的事情就是离开前台,因为 ART 的垃圾收集器只会在您的应用程序处于后台时压缩内存。在 Android 8.0+ 上,即使您在前台,ART 的垃圾收集器也会压缩内存。

除此之外,目标是每周或类似地启动一个新进程,这样您就可以获得一个新堆。