【问题标题】:Out of memory error android due to fragmentation after 20+days20+天后由于碎片导致内存不足错误android
【发布时间】:2018-11-10 11:15:32
【问题描述】:

我制作了一个在咖啡机上运行的应用程序。
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 应用程序运行碎片整理?

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

【问题讨论】:

  • 你读过this answer吗?如果这没有帮助,您将需要提供有关您的应用程序功能的更多信息,然后才能帮助您。没有通用的这是您在应用程序上解决此问题的方法,您什么都没告诉我们答案。见How to Askminimal reproducible example

标签: android memory out-of-memory fragmentation


【解决方案1】:

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

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

除此之外,目标是每周启动一次新进程或其他什么,这样你就会得到一个新的堆。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    • 2012-03-16
    • 2011-05-05
    • 1970-01-01
    • 2013-04-18
    • 1970-01-01
    • 2022-06-12
    相关资源
    最近更新 更多