Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions docs/platforms/android/configuration/memory-limiter.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
---
title: Memory Limiter
sidebar_order: 5
description: Learn how to detect process deaths caused by Android's Memory Limiter with the Sentry Android SDK.
---

<Alert title="Experimental">

The Memory Limiter integration is experimental. It's available in Sentry Android SDK version ≥ `8.57.0`, and Android API level ≥ 37.

</Alert>

Android 17 introduced the Memory Limiter, a system service available on supported devices that's responsible for managing per-app memory budgets and slowing down or terminating apps that exceed them. Terminations don't produce a Java exception or a stack trace, which makes them easy to miss if you're only looking for traditional crashes.

Sentry's Memory Limiter integration generates fatal Sentry events for Memory Limiter terminations by scanning [ApplicationExitInfo](https://developer.android.com/reference/android/app/ApplicationExitInfo) records written by the Android OS.

To learn more about Memory Limiter, see [Google's documentation](https://source.android.com/docs/core/perf/memory-limiter) and the [Android Developers Blog](https://android-developers.googleblog.com/2026/08/app-broader-memory-limits.html).

## Prerequisites

- You're using Sentry Android SDK version `8.57.0` or later.
- The device is running Android 17 (API level 37) or later.
- The SDK has a cache directory available.
- You enable the integration explicitly. (It's disabled by default.)

## Enable the Memory Limiter Integration

You can enable the integration in your `AndroidManifest.xml`:

```xml {filename:AndroidManifest.xml}
<application>
<meta-data android:name="io.sentry.memory-limiter.enable" android:value="true" />
</application>
```

Or when you initialize the SDK:

```kotlin {tabTitle:Kotlin}
SentryAndroid.init(this) { options ->
options.isMemoryLimiterEnabled = true
}
```

```java {tabTitle:Java}
SentryAndroid.init(this, options -> {
options.setMemoryLimiterEnabled(true);
});
```

## How It Works

When the Memory Limiter terminates a process, info about that process is recorded by the Android OS in the form of an `ApplicationExitInfo` entry, tracked by the `ActivityManager` system service.

On the next app start, the SDK searches all exit info records for Memory Limiter deaths. If it finds a match, the SDK creates a synthetic fatal event with the `MemoryLimitExceeded` exception type. For the latest matching exit, the SDK also backfills persisted context from the previous process when that data is available.

## Historical Memory Limiter Exits

By default, the SDK reports only the latest matching Memory Limiter exit. If you also want older retained exits from the same Android history, enable historical reporting:

```xml {filename:AndroidManifest.xml}
<application>
<meta-data android:name="io.sentry.memory-limiter.enable" android:value="true" />
<meta-data android:name="io.sentry.memory-limiter.report-historical" android:value="true" />
</application>
```

```kotlin {tabTitle:Kotlin}
SentryAndroid.init(this) { options ->
options.isMemoryLimiterEnabled = true
options.isReportHistoricalMemoryLimiterExits = true
}
```

```java {tabTitle:Java}
SentryAndroid.init(this, options -> {
options.setMemoryLimiterEnabled(true);
options.setReportHistoricalMemoryLimiterExits(true);
});
```

Historical exits are lighter-weight reports. Unlike the latest retained exit, they aren't enriched with persisted Sentry context from the previous process.

## What You'll See in Sentry

Memory Limiter reports appear as fatal events with:

- Exception type `MemoryLimitExceeded`
- Mechanism type `AppExitInfo` for the latest exit, or `HistoricalAppExitInfo` for older retained exits
- The original Android exit description stored on the event's `mechanism`
- Memory Limiter-specific mechanism data such as `memory_limit_class` and `process_importance`

![Memory Limiter Event in Sentry](./img/memory-limiter-event-in-sentry.png)

The `memory_limit_class` value is a best-effort classification derived from `process_importance` and the table shown [here](https://source.android.com/docs/core/perf/memory-limiter#process-monitoring). It consists of three buckets:

- `visible`
- `not_visible`
- `cached`

These fields can help you approximate the memory capacity allocated to your process before it was killed and whether it was visible to users.

Values for `process_importance` are taken from [`ApplicationExitInfo.importance`](<https://developer.android.com/reference/android/app/ApplicationExitInfo#getImportance()>). Memory Limiter events are grouped by `process_importance` in Sentry's issues feed:

![Memory Limiter Grouping in Sentry](./img/memory-limiter-grouping.png)

## Release Health and Sessions

If you're using <PlatformLink to="/configuration/releases/">Release Health</PlatformLink>, the latest recovered Memory Limiter exit also marks the previous session as `abnormal` on the next app launch.

That keeps release health closer to what users experienced instead of treating the terminated session as a healthy exit.

For more about session states, see <Link to="/product/releases/health/#session-status">Session Status</Link>.
24 changes: 24 additions & 0 deletions docs/platforms/android/configuration/options.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,30 @@ When enabled, the SDK assigns a static fingerprint to ANR events whose stack tra

</SdkOption>

## Memory Limiter Options

<SdkOption name="memoryLimiterEnabled" type="bool" defaultValue="false" availableSince="8.57.0">

Enables experimental detection of Android Memory Limiter process deaths through retained [ApplicationExitInfo](https://developer.android.com/reference/android/app/ApplicationExitInfo) records.

When enabled, the SDK checks for Memory Limiter terminations on the next app start and reports the latest match as a fatal event. If release health is enabled, the previous session is also marked as abnormal.

This feature is available only on supported devices running on Android 17 (API level 37) and higher. See <PlatformLink to="/configuration/memory-limiter/">Memory Limiter</PlatformLink> for setup details and limitations.

AndroidManifest.xml key: `io.sentry.memory-limiter.enable`.

</SdkOption>

<SdkOption name="reportHistoricalMemoryLimiterExits" type="bool" defaultValue="false" availableSince="8.57.0">

Reports older retained Memory Limiter process deaths in addition to the latest one.

Historical Memory Limiter terminations are not enriched with persisted context from the previous process. This option only takes effect when <PlatformIdentifier name="memoryLimiterEnabled" /> is enabled.

AndroidManifest.xml key: `io.sentry.memory-limiter.report-historical`.

</SdkOption>

## Transaction-Based Profiling Options

This mode will eventually be deprecated, and it's recommended to upgrade to <PlatformLink to="/configuration/options/#ui-profiling-options">UI Profiling</PlatformLink>. The same behaviour, without the 30 seconds limitation, can be achieved with the `trace` <PlatformLink to="/configuration/options/#profile-lifecycle">profile lifecycle</PlatformLink> option. In order to upgrade to UI Profiling, you also need to remove the transaction-based options from your configuration.
Expand Down
1 change: 1 addition & 0 deletions docs/platforms/android/features/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Let us know if you have feedback by filing a <Link to="https://github.com/getsen
- <PlatformLink to="/configuration/integrations/apollo">Apollo request spans</PlatformLink>.
- Distributed tracing through <PlatformLink to="/configuration/integrations/okhttp">OkHttp</PlatformLink> and <PlatformLink to="/configuration/integrations/apollo">Apollo</PlatformLink> integrations.
- <PlatformLink to="/configuration/app-not-respond">Application Not Responding (ANR)</PlatformLink>, reported if the application is blocked for more than five seconds.
- <PlatformLink to="/configuration/memory-limiter">Memory Limiter</PlatformLink>, which reports process kills caused by Android's per-app memory limits on supported devices.
- <PlatformLink to="/configuration/integrations/okhttp/#http-client-errors">HTTP Client Errors</PlatformLink>.
- <PlatformLink to="/enriching-events/screenshots">Screenshot attachments for errors</PlatformLink>.
- <PlatformLink to="/enriching-events/viewhierarchy">View Hierarchy attachments for errors</PlatformLink>.
Expand Down
1 change: 1 addition & 0 deletions docs/platforms/android/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,4 @@ class MyActivity : AppCompatActivity() {
- <PlatformLink to="/enhance-errors">Learn how to enhance stack traces of your Sentry errors</PlatformLink>
- <PlatformLink to="/enriching-events">Enrich events with additional context to make debugging simpler</PlatformLink>
- <PlatformLink to="/configuration/app-not-respond">Diagnose ANRs</PlatformLink> with profiling and automatic fingerprinting
- Monitor <PlatformLink to="/configuration/memory-limiter">Memory Limiter process deaths</PlatformLink> on supported Android 17+ devices
Loading