将largeHeap设置为true有什么好处? [英] What are advantages of setting largeHeap to true?

查看:317
本文介绍了将largeHeap设置为true有什么好处?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量课程的应用程序;还包括许多库,由于内存问题,我正在设置android:largeHeap="true",并附加了我的清单文件代码.

I have an application with large number of classes & also many libraries are included, I am setting android:largeHeap="true" as i am getting memory issue, My Manifest file code is attached.

<application
        android:name=".MyApplication"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="My Huge Application"
        android:largeHeap="true"
        android:logo="@drawable/logo"
        android:screenOrientation="portrait"
        android:theme="@style/AppTheme" >
</application>

我不得不问这是一个好习惯吗? 请指出使用它的优点和缺点(优点和缺点).

I had to ask that is this a good practice? Kindly suggest advantages and disadvantages (pros and cons) of using it.

推荐答案

在这里参加聚会太晚了,但是我还是愿意提供0.02 $.
使用它不是一个好主意 android:largeHeap="true"这是从Google摘录中解释的内容,

Way too late for the party here, but i will offer my 0.02$ anyways.
It's not a good idea to use android:largeHeap="true" here's the extract from google that explains it,

但是,请求大堆的能力仅适用于 一小部分可以证明需要消耗更多RAM的应用程序(例如 作为大型照片编辑应用程序).永远不要简单地请求大堆 因为您的内存已用完,并且需要快速修复,所以您应该 仅当您确切知道所有内存的位置时才使用它 分配以及为什么必须保留它.但是,即使您有信心 您的应用可以证明大堆的合理性,您应该避免将其请求给 尽一切可能.使用额外的内存将越来越多 损害整体用户体验,因为垃圾 收集将花费更长的时间,并且系统性能可能会变慢 任务切换或执行其他常见操作.

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.

这是文档的完整链接 https://developer.android.com/training/articles/memory.html

here's the complete link of the documentation https://developer.android.com/training/articles/memory.html

更新

在与out of memory errors进行了令人发指的合作之后,我会说将其添加到清单中以避免oom问题不是一种罪过,就像@Milad指出的那样,它不会影响应用的正常工作

After working excrutiatingly with out of memory errors i would say adding this to the manifest to avoid the oom issue is not a sin, also like @Milad points out below it does not affect the normal working of the app

更新2

以下是out of memory errors

1)使用android提供的这些回调 onLowMemory onTrimMemory(int) 并清除图像缓存(如毕加索,滑行,壁画...).您可以在此处这里
4)在生产前必须定期使用皮棉,以确保代码流畅且 体积不大

1) Use these callback that android gives onLowMemory, onTrimMemory(int) and clear the cache of image like (picasso, glide, fresco....) you can read more about them here and here
2) compress your files(images, pdf)
3) read about how to handle bitmap more efficiently here
4) Use lint regularly before production pushes to ensure code is sleek and not bulky

这篇关于将largeHeap设置为true有什么好处?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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