gpt4 book ai didi

android - 使用android :largeHeap ="true"?有什么缺点

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:06:45 24 4
gpt4 key购买 nike

最近我将我的应用程序的最大内存峰值从 100 MB 减少到 45 MB,我很好奇使用 android:largeHeap="true"除了有可能将其他应用程序推出内存?如果大小没有增长到足以证明推出其他应用程序是合理的,这不是一个很好的故障保护,例如,如果您的应用程序只打算在一次崩溃可能是灾难性的 session 上使用四天?还是我正在寻找其他一些骗局?

最佳答案

作为this training guide指出,

"Using the extra memory will increasingly be to the detriment of the overall user experience because garbage collection will take longer and system performance may be slower when task switching or performing other common operations."

我认为这是一个非常有效的问题,让我对此添加一些额外的解释。

1) 更长的垃圾收集时间:

很难衡量更大的堆需要多少额外时间。因为很多事情都会影响垃圾收集时间。使用哪个 Android 运行时(Dalvik 或 ART)会影响垃圾收集时间(您可以在 here 查看更多信息)。垃圾回收在 different Android version 上的执行方式也不同。 .但可以肯定的是,更大的堆会使垃圾收集时间更长。因为垃圾收集器基本上必须遍历整个 Activity 对象集。如果你好奇,你可以从Memory management for Android Apps了解更多关于这个话题。 2011 年 Google I/O session 。正如 session 幻灯片中所述,垃圾收集暂停时间约为 5 毫秒。你可能认为几毫秒没什么大不了的,但每一毫秒都很重要。 Android 设备必须每 16 毫秒更新一次屏幕,较长的 GC 时间可能会使您的帧处理时间超过 16 毫秒的障碍,这会导致明显的卡顿。

2) 任务切换较慢:

如解释here ,

the system may kill processes in the LRU cache beginning with the process least recently used, but also giving some consideration toward which processes are most memory intensive.

因此,如果您使用更大的堆,您的进程在后台时更有可能被杀死,这意味着当用户想要从其他应用切换到您的应用时可能需要更长的时间。当您的进程处于前台时,后台进程也更有可能被踢出,因为您的应用程序需要更大的内存。这意味着从您的应用程序切换到其他应用程序也需要更长的时间。这些显然对用户不利。

关于android - 使用android :largeHeap ="true"?有什么缺点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26189619/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com