gpt4 book ai didi

android - 应用程序可以使用的最大 RAM 量是多少?

转载 作者:太空宇宙 更新时间:2023-11-04 10:54:10 24 4
gpt4 key购买 nike

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

我想知道的是:

  • 最大内存量是多少(以兆字节为单位/作为Android 应用程序(非系统应用程序)可以使用的总 RAM 的百分比
  • Android 版本之间有什么差异吗?
  • 设备制造商方面是否存在任何差异?

最重要的是:

  • 当系统确定应用在运行时可以使用多少 RAM(假设每个应用的最大内存不是静态数字)时,会考虑什么/它取决于什么

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

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

是什么让我很好奇:

这两个限制都非常低。

我最近刚刚下载了 Android Task Manager检查我的设备 RAM。我注意到有些应用程序使用大约 40-50 MB 的 RAM,这显然超过了提到的最大 RAM 使用量(假设为 32 MB)。那么 Android 如何确定应用程序可以使用多少 RAM?应用程序怎么可能超出该限制?

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

免责声明:我与 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?

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

Are there any differences between the Android versions?

是的,多年来操作系统要求不断增加,设备也必须进行调整以适应。

Are there differences concerning the manufacturer of the device?

是的,只要制造商制造设备,并且尺寸因设备而异。

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

我不知道“副作用”是什么意思。

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

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

How is it possible that apps exceed that limit?

您假设该应用程序的作者知道他在做什么。考虑到 memory usage of an app is difficult for a core Android engineer to determine ,我不认为相关应用程序一定能提供特别准确的结果。

话虽如此, native 代码 (NDK) 不受堆限制。而且,自 Android 3.0 以来,应用程序可以请求“大堆”,通常在数百 MB 范围内,但这对于大多数应用程序来说被认为是糟糕的形式。

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

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

关于android - 应用程序可以使用的最大 RAM 量是多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47472857/

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