应用程序可以使用的最大 RAM 量是多少? [英] What is the maximum amount of RAM an app can use?

查看:28
本文介绍了应用程序可以使用的最大 RAM 量是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Android操作系统的内存管理的这个问题很好奇,所以我希望得到关于该主题的非常详细的答案.

I am quite curious about this question concerning the memory management of the Android operating system so I hope for a quite detailed answer on that topic.

我想知道的:

  • 什么是最大内存(以兆字节为单位/作为一个 Android 应用程序(不是系统应用程序)可以使用的 占总 RAM 的百分比?
  • Android 版本之间有什么区别吗?
  • 设备的制造商是否存在任何差异?
  • What is the maximum amount of memory (in megabytes / as percentage of the total RAM) that an Android application (that is not a system app) can use?
  • Are there any differences between Android versions?
  • Are there any differences concerning the manufacturer of the device?

最重要的是:

  • 考虑什么/它依赖什么当涉及到系统确定应用程序在运行时可以使用多少内存(假设每个应用程序的最大内存不是静态数字)?
  • What is considered / what does it depend on when it comes to the system determining how much RAM an app can use at runtime (assuming that the memory maximum per app is not a static number)?

到目前为止我所听到的(直到 2013 年):

What I have heard so far (up until 2013):

  • 早期的 Android 设备每个应用的上限为 16MB
  • 后来这个上限增加到 24MB 或 32MB

什么让我很好奇:

这两个限制都非常低.

我最近刚刚下载了 Android 任务经理检查我的设备内存.我注意到有些应用程序使用了大约 40-50 兆字节的 RAM,这显然比上面提到的最大 RAM 使用量(假设为 32 MB)还要多.那么Android是如何确定一个应用可以使用多少内存的呢?应用怎么可能超过这个限制?

I have just recently downloaded the Android Task Manager to check my devices RAM. What I have noticed is that there are applications using around 40-50 megabytes of RAM, which is obvioulsy more than the mentioned maximum RAM usage of let's say 32 MB. So how does Android determine how much RAM an app can use? How is it possible that apps exceed that limit?

此外,我注意到我的一些应用程序在使用大约 30-40 兆字节时崩溃(被系统杀死?)并带有 OutOfMemoryException.另一方面,我的手机上运行的应用程序使用 100 MB 和更多 一段时间后(可能是由于内存泄漏)不会崩溃或被杀死.因此,在确定可以节省多少 RAM 时,这显然还取决于应用程序本身.这怎么可能?(我使用 768 MB RAM 的 HTC One S 进行了测试)

Furthermore, I noticed that some apps of mine crash (killed by the system?) with an OutOfMemoryException when using around 30-40 Megabytes. On the other hand, I have apps running on my phone using 100 MB and more after some time (probably due to memory leaks) that do not crash or get killed off. So it obviously also depends on the app itself when it comes to determining how much RAM can be spared. How is this possible? (I conducted my tests with an HTC One S with 768 MB RAM)

免责声明:我与 Android 任务管理器应用没有任何关联.

推荐答案

Android 应用程序(不是系统应用程序)可以使用的最大内存量(以 MB 为单位/占总 RAM 的百分比)是多少?

What is the maximum amount of memory (in Megabytes / as percentage of the total RAM) that an Android application (that is not a system app) can use?

这因设备而异.getMemoryClass() on ActivityManager 将为您提供运行代码的设备的值.

That varies by device. getMemoryClass() on ActivityManager will give you the value for the device your code is running upon.

Android 版本之间有什么区别吗?

Are there any differences between the Android versions?

是的,因为操作系统要求多年来一直在增加,并且设备必须进行调整以匹配.

Yes, insofar as OS requirements have increased over the years, and devices have to adjust to match.

设备制造商是否存在差异?

Are there differences concerning the manufacturer of the device?

是的,就制造商制造设备而言,尺寸因设备而异.

Yes, insofar as manufacturers manufacture devices, and the size varies by device.

在确定应用可以使用多少 RAM 时,会考虑哪些附带因素"?

Which "side factors" are taken into consideration when it comes to determining how much RAM an app can use?

我不知道附带因素"是什么意思.

I have no idea what "side factors" means.

早期设备的每个应用程序上限为 16MB;后来的设备将其增加到 24MB 或 32MB

Early devices had a per-app cap of 16MB; Later devices increased that to 24MB or 32MB

差不多吧.屏幕分辨率是一个重要的决定因素,因为更大的分辨率意味着更大的位图,因此平板电脑和高分辨率手机往往会具有更高的值.例如,您将看到具有 48MB 堆的设备,如果存在高于该值的值,我不会感到惊讶.

That's about right. Screen resolution is a significant determinant, as larger resolutions mean larger bitmaps, and so tablets and high-resolution phones will tend to have higher values yet. For example, you will see devices with 48MB heaps, and I wouldn't be surprised if there are values higher than that.

应用怎么可能超过这个限制?

How is it possible that apps exceed that limit?

您假设该应用程序的作者知道他在做什么.考虑到 应用的内存使用是核心 Android 工程师难以确定,但我不认为相关应用一定能提供特别准确的结果.

You assume that the author of that app knows what (s)he is doing. Considering that memory usage of an app is difficult for a core Android engineer to determine, I would not assume that the app in question is necessarily providing particularly accurate results.

话虽如此,本机代码 (NDK) 不受堆限制.而且,从 Android 3.0 开始,应用可以请求大堆",通常在数百 MB 范围内,但对于大多数应用来说,这被认为是糟糕的形式.

That being said, native code (NDK) is not subject to the heap limit. And, since Android 3.0, apps can request a "large heap", usually in the hundreds of MB range, but that's considered poor form for most apps.

此外,我注意到我的一些应用程序在使用大约 30-40 兆字节时崩溃并出现 OutOfMemoryException.

Furthermore, I noticed that some apps of mine crash with an OutOfMemoryException when using around 30-40 Megabytes.

请记住,Android 垃圾收集器不是压缩垃圾收集器.异常确实应该是 CouldNotFindSuffcientlyLargeBlockOfMemoryException,但这可能被认为过于冗长.OutOfMemoryException 意味着您无法分配您请求的块,而不是您已经完全耗尽了您的堆.

Bear in mind that the Android garbage collector is not a compacting garbage collector. The exception really should be CouldNotFindSufficientlyLargeBlockOfMemoryException, but that was probably deemed too wordy. OutOfMemoryException means that you could not allocate your requested block, not that you have exhausted your heap entirely.

这篇关于应用程序可以使用的最大 RAM 量是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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