---
name: "onMemoryWarning"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onMemoryWarning

> [VERSION] BaseKit >= 2.3.2

> [PLATFORM] iOS, Android

> ⚡ **Supports Promise** — Returns a Promise when success / fail / complete callbacks are omitted.

### Description

Listen for low-memory warning events. This event is triggered when iOS/Android sends a memory warning to the Miniapp process. Triggering this event does not mean the Miniapp will be killed; in most cases it is only a warning. Developers can free unnecessary resources upon receiving the notification to avoid further memory pressure.

### Parameters

`(listener: Function)`

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `listener` | `(params: Object) => void` | Yes | - | Event listener callback function |

##### onMemoryWarning.listener(params) properties

| Property | Type | Required | Default | Since | Description |
| --- | --- | --- | --- | --- | --- |
| `level` | `number` | Yes | - | `2.3.2` | Memory warning level, Android-only, corresponds to system macro definitions |


### Examples

```tsx
// Listen for low-memory warnings; when the system is low on memory, the callback returns the warning level (level is Android-only)
ty.onMemoryWarning(e => {
  console.log("Memory warning received, level:", e.level);
});
// Warnings are triggered by the system; keep the listener active for a while
await new Promise(resolve => setTimeout(resolve, 3000));
```
