由于 20 多天后的碎片,内存不足错误 android [英] Out of memory error android due to fragmentation after 20+days

查看:80
本文介绍了由于 20 多天后的碎片,内存不足错误 android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

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

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.

推荐答案

有没有办法以编程方式在内存 android 应用程序上运行碎片整理?

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

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

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.

这篇关于由于 20 多天后的碎片,内存不足错误 android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆