English
Listen for out-of-memory warning events.
This event is triggered when iOS/Android issues a memory warning to the MiniApp process. There is an alarm level division under Android, but there is no level division under iOS.
Platform Difference Description
| App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
|---|---|---|---|---|---|---|---|---|---|---|
| Android 3.6.9+、iOS 3.6.11+ | x | √ | √ | √ | √ | √ | √ | √ | x | √ |
| HarmonyOS |
|---|
| x |
This API is uni ext api, you need to download the plug-in: https://ext.dcloud.net.cn/plugin?id= 10071
CALLBACK return parameter:
| parameter name | type | description |
|---|---|---|
| level | Number | Only Android has this field, which corresponds to the system memory alarm level macro definition |
Legal values for level
| Value | Corresponding Android alarm value | Description |
|---|---|---|
| 5 | TRIM_MEMORY_RUNNING_MODERATE | The process is in the middle of the background LRU list; freeing memory can help the system keep other processes running later in the list for better overall performance. |
| 10 | TRIM_MEMORY_RUNNING_LOW | The process is not a consumable background process, but the device is low on memory |
| 15 | TRIM_MEMORY_RUNNING_CRITICAL | The process is not a consumable background process, but the device is running very low on memory and is about to be unable to keep any background processes running. |
code example
const callback = function (res) {
console.log(res,'onMemoryWarningReceive');
}
uni.onMemoryWarning(callback);
Cancel listening to insufficient memory warning events. If no callback is passed in, all listeners will be cancelled.
Platform Difference Description
| App | H5 | 微信小程序 | 支付宝小程序 | 百度小程序 | 抖音小程序、飞书小程序 | QQ小程序 | 快手小程序 | 京东小程序 | 元服务 | 小红书小程序 |
|---|---|---|---|---|---|---|---|---|---|---|
| x | x | √ | √ | √ | √ | x | √ | √ | x | √ |
| HarmonyOS |
|---|
| x |
| Property | Type | Description |
|---|---|---|
| Callback function | Function | Callback function for low memory alarm event |
code example
const callback = function (res) {
console.log(res);
}
uni.onMemoryWarning(callback);
// Just pass in the same function as onMemoryWarning
uni.offMemoryWarning(callback);
Tips
CALLBACK is the CALLBACK passed in when calling uni.onMemoryWarning