title: Taro.onMemoryWarning(callback)

sidebar_label: onMemoryWarning

Listens on the insufficient memory alarm event.

This event is triggered when iOS/Android sends an insufficient memory alarm to the Mini Program process. Triggering this event does not mean that the Mini Program will be terminated. In most cases, it is only an alarm. Developers can reclaim some unnecessary resources after receiving the alarm to free up memory space.

Reference

Type

  1. (callback: Callback) => void

Parameters

Callback

The callback function for the insufficient memory alarm event.

  1. (result: CallbackResult) => void
Property Type
result CallbackResult

CallbackResult

Property Type Description
level 5 | 10 | 15 Memory alarm level, only available in Android. It corresponds to the system macro definition.

level

Property Description
5 TRIM_MEMORY_RUNNING_MODERATE
10 TRIM_MEMORY_RUNNING_LOW
15 TRIM_MEMORY_RUNNING_CRITICAL

Sample Code

  1. Taro.onMemoryWarning(function () {
  2. console.log('onMemoryWarningReceive')
  3. })

API Support

API WeChat Mini-Program H5 React Native
Taro.onMemoryWarning ✔️