有关于android:largeHeap 的一些观点

来源:互联网 发布:数据库死锁解决 编辑:程序博客网 时间:2024/05/17 07:11

有关于android:largeHeap 的一些观点

来源于:What are advantages of setting largeHeap to true?

先说结论:android:largeHeap=”true”可以为你的程序提供更大的内存,如果你想让你的程序更少遇到”OOM”的问题的话,可以考虑用这个方法来直接偷懒。

下面是Google对于不建议使用android:largeHeap=”true”的描述:

However, the ability to request a large heap is intended only for a small set of apps that can justify the need to consume more RAM (such as a large photo editing app). Never request a large heap simply because you’ve run out of memory and you need a quick fix—you should use it only when you know exactly where all your memory is being allocated and why it must be retained. Yet, even when you’re confident your app can justify the large heap, you should avoid requesting it to whatever extent possible. 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. 你可能会丧失一些帧,会导致一些视觉残留。 更大的内存导致GC花费的时间会增加,通常来说,GC暂停时间大约是5ms,可能你觉得毫秒而已,没什么大不了的。但是Android设备每16ms就会刷新一次屏幕,这么以来,更长的GC时间将让你的帧处理时间超过16ms的界限,这就可能导致一个视觉残留。
  2. 并且在切换APP的时候会变得更慢。因为使用了过多的内存,那么如果在后台的时候,就更可能会被系统回收。那么当用户从其他的应用切回你的应用的时候,会花费更长的时间。
0 0