MemoryBudget


class MemoryBudget : Parcelable
kotlin.Any
   ↳ android.content.pm.MemoryBudget

Memory budget information for an application. entries are retrieved from <memory-budget> entries in an application's manifest, and can be obtained through ApplicationInfo.getMemoryBudgets.

A MemoryBudget that is declared in the Android manifest sets a ceiling on the memory available to the package or to a process within the package. MemoryBudget declarations may appear at the application level and at the process level. The two are independent and neither overrides the other. In practice, however, the smaller budget dominates.

Every MemoryBudget has a state and a feature; these two attributes determine if and when the MemoryBudget is applicable.

  • The state is the operational state of the process or the application, and is one of Foreground, Perceptible, or Background.
  • The feature selects for device form-factor and is one of Unspecified, TV, Auto, and Watch.
A MemoryBudget is applicable to a process if its feature is Unspecified or if its feature matches the device's form-factor. A MemoryBudget applies to a process if it is applicable to the process and the MemoryBudget state is less than or equal to the operational state of the process. Applications also have state, which is roughly the lowest state of any process running in the application.

A MemoryBudget declares an upper bound on the amount of memory the process or application may use. The upper bound is computed from three factors:

  • maxMb is a baseline amount of memory, expressed in MiB. This must be positive.
  • additionalBytesPerPixel is a scaling factor: bytes per display pixel. This must be non-negative and defaults to zero.
  • additionalMbPerDensity is a scaling factor: MiB times display density. This must be non-negative and defaults to zero.
The actual limit is calculated as the maxMb value plus the scale factors applied to the default display of the device.

If a process RSS exceeds its declared budget then the kernel will force it to drop memory. This usually means dropping file cache pages but it may also mean that some memory will be moved to swap. In most cases this happens without any impact on the process, but if the process is actively using more memory than the budget limit, the process will slow down as pages are swapped out and then back in. In the limit, the process may ANR.

Summary

Constants
static Int

Indicates that this MemoryBudget applies to the automotive form factor.

static Int

Indicates that this MemoryBudget applies to the TV form factor.

static Int

Indicates that this MemoryBudget is generic, and can apply to any form factor.

static Int

Indicates that this MemoryBudget applies to the watch form factor.

static Int

Indicates that this MemoryBudget can apply to a process that is in the background.

static Int

Indicates that this MemoryBudget can apply to a process that is in the foreground (or in a less important state).

static Int

Indicates that this MemoryBudget can apply to a process that is perceptible (or in a less important state).

Inherited constants
Public methods
Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.

Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

Long

Returns the additional bytes per pixel that this MemoryBudget's limit will be raised by.

Long

Returns the additional memory (in MiB) that this MemoryBudget's limit will be raised by, based on the screen density of the device.

Int

Returns the form factor to which this MemoryBudget applies.

Long

Returns the memory limit (in MiB) that this MemoryBudget represents.

Int

Returns the process state in which this MemoryBudget applies.

Int

Returns a hash code value for the object.

String

Returns a string representation of the object.

Unit
writeToParcel(dest: Parcel, flags: Int)

Flatten this object in to a Parcel.

Properties
static Parcelable.Creator<MemoryBudget!>

Constants

FEATURE_AUTOMOTIVE

static val FEATURE_AUTOMOTIVE: Int

Indicates that this MemoryBudget applies to the automotive form factor.

Value: 1

FEATURE_LEANBACK

static val FEATURE_LEANBACK: Int

Indicates that this MemoryBudget applies to the TV form factor.

Value: 2

FEATURE_UNSPECIFIED

static val FEATURE_UNSPECIFIED: Int

Indicates that this MemoryBudget is generic, and can apply to any form factor. This is the default if "feature" is not specified in the manifest.

Value: 0

FEATURE_WATCH

static val FEATURE_WATCH: Int

Indicates that this MemoryBudget applies to the watch form factor.

Value: 3

STATE_BACKGROUND

static val STATE_BACKGROUND: Int

Indicates that this MemoryBudget can apply to a process that is in the background.

Value: 300

STATE_FOREGROUND

static val STATE_FOREGROUND: Int

Indicates that this MemoryBudget can apply to a process that is in the foreground (or in a less important state). This is the default if "state" is not specified in the manifest.

Value: 100

STATE_PERCEPTIBLE

static val STATE_PERCEPTIBLE: Int

Indicates that this MemoryBudget can apply to a process that is perceptible (or in a less important state).

Value: 200

Public methods

describeContents

fun describeContents(): Int

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. For example, if the object will include a file descriptor in the output of writeToParcel(Parcel,int), the return value of this method must include the CONTENTS_FILE_DESCRIPTOR bit.

Return
Int a bitmask indicating the set of special object types marshaled by this Parcelable object instance.
Value is either 0 or

equals

fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj the reference object with which to compare.
Return
Boolean true if this object is the same as the obj argument; false otherwise.

getAdditionalBytesPerDisplayPixel

fun getAdditionalBytesPerDisplayPixel(): Long

Returns the additional bytes per pixel that this MemoryBudget's limit will be raised by.

Return
Long The additionalBytesPerDisplayPixel attribute.

getAdditionalMbPerDensity

fun getAdditionalMbPerDensity(): Long

Returns the additional memory (in MiB) that this MemoryBudget's limit will be raised by, based on the screen density of the device. The formula used for calculating the additional memory is (N * { ldpi=0.75, mdpi=1.0, hdpi=1.5, xhdpi=2... }).

Return
Long The additionalMbPerDensity attribute.

getFeature

fun getFeature(): Int

Returns the form factor to which this MemoryBudget applies.

Return
Int The form factor to which this MemoryBudget applies.
Value is one of the following:

getMaxMb

fun getMaxMb(): Long

Returns the memory limit (in MiB) that this MemoryBudget represents.

Return
Long The memory limit (in MiB) that this MemoryBudget represents.

getState

fun getState(): Int

Returns the process state in which this MemoryBudget applies.

Return
Int The process state in which this MemoryBudget applies.
Value is one of the following:

hashCode

fun hashCode(): Int

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Return
Int a hash code value for this object.

toString

fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.

writeToParcel

fun writeToParcel(
    dest: Parcel,
    flags: Int
): Unit

Flatten this object in to a Parcel.

Parameters
dest Parcel: This value cannot be null.
flags Int: Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.
Value is either 0 or a combination of the following:

Properties

CREATOR

static val CREATOR: Parcelable.Creator<MemoryBudget!>