---
name: "onMemoryWarning"
mode: "kit"
versionRequirements:
  - { name: "BaseKit", version: "2.3.2" }
  - { name: "@ray-js/ray", version: "0.3.23" }
platform:
  - "iOS"
  - "Android"
async: true
---

## onMemoryWarning

> [VERSION] BaseKit >= 2.3.2 | @ray-js/ray >= 0.3.23

> [PLATFORM] iOS, Android

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

### Description

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

### Parameters

`(listener: Function)`

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

##### 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

#### Demo

```tsx
import { onMemoryWarning } from '@ray-js/ray'

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