我制作了一个在咖啡机上运行的应用程序。
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 应用程序上运行 fragment 整理?
所需的时间应该不是问题,因为机器会进入待机或环保模式。
我看到的是可用内存绰绰有余。
最佳答案
Is there a way to run a defragmentation on memory android application programmatically?
没有。在 Android 5.0-7.1 上,你能做的最好的事情就是离开前台,因为 ART 的垃圾收集器只会在你的应用程序在后台时压缩内存。在 Android 8.0+ 上,即使您在前台,ART 的垃圾收集器也会压缩内存。
除此之外,目标是每周或类似地启动一个新进程,这样您就可以获得一个新堆。
关于android - 由于 20 天以上的 fragment 化导致内存不足错误 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50624338/