在Android中使用largeheap是否体现了良好的习惯? [英] Is using largeheap in Android manifest a good practice?

查看:767
本文介绍了在Android中使用largeheap是否体现了良好的习惯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在NDK中进行开发.它挂在Galaxy S3中.为了进行测试,我将android:largeheap = "true"放在了Manifest中.这样就没有悬而未决的问题了. 使用largeHeap="true"是一个好习惯吗?

I am developing in NDK. It hangs in Galaxy S3. For testing I put android:largeheap = "true" in Manifest. Then there was no hanging issue. Is it a good practice to use largeHeap="true"?

Google是否有可能由于此标记而拒绝我的构建,并且 如何防止不使用largeheap="true"挂起我的应用?

Is there any chance that Google rejects my build due to this tag and how can I prevent my app from hanging without using largeheap="true"?

推荐答案

简短回答

不,如果需要,这不是一个坏的约定,因为它已经存在.

Short Answer

No, if you need it it is not a bad pactise because it is there for it.

官方文档状态

您的应用程序流程是否应使用大型 达尔维克堆.这适用于为 应用.
它仅适用于加载到 过程;如果您使用共享用户ID允许多个 应用程序要使用一个进程,它们都必须使用此选项 一致,否则它们将产生不可预测的结果.
大多数应用应 不需要这个,而应该专注于减少他们的整体 内存使用情况以提高性能.启用它也不会 保证可用内存的固定增加,因为某些设备 受它们的总可用内存限制.

Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application.
It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use this option consistently or they will have unpredictable results.
Most apps should not need this and should instead focus on reducing their overall memory usage for improved performance. Enabling this also does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.

一些开发人员使用它来避免OOM过度,因此,如果您只是为了避免某些 OOM 而使用它,则这是非常糟糕的做法.

Some developers uses it to avoid OOM excepetion, so if you are using it just to avoid some OOM it is a very very bad pactice.

请不要仅仅因为内存不足而请求大堆,并且 您需要快速修复.仅当您完全知道时才应使用它 您所有内存的分配位置以及为什么必须保留

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


如果您实际上需要更多空间,可以使用它,则可以使用 getLargeMemoryClass() 大堆.


If you actually need more space it's ok to use it, you can use getMemoryClass() to check the heap and getLargeMemoryClass() large heap.

但是,如果您可以避免使用largeHeap,那将是最好的方法,因为官方文档仍在继续:

But if you can avoid using the largeHeap it would be the best way to go, as the official documentation continues:

但是,即使您确信自己的应用程序可以证明大堆的合理性, 您应尽可能避免提出要求.使用 额外的内存将越来越不利于整个用户 经验,因为垃圾收集将花费更长的时间和系统 切换任务或执行其他任务时,性能可能会变慢 常见的操作.
另外,大堆大小不是 在所有设备上都相同,并且可能与常规堆完全相同 大小.因此,即使您确实要求较大的堆大小,也应该调用 getMemoryClass()检查常规堆大小并努力始终 保持在该限制之下.

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.
Additionally, the large heap size is not the same on all devices and may be exactly the same as the regular heap size. So even if you do request the large heap size, you should call getMemoryClass() to check the regular heap size and strive to always stay below that limit.

我还建议您在这里 管理应用程序的内存

I also suggest you to have a look here Managing Your App's Memory

这篇关于在Android中使用largeheap是否体现了良好的习惯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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