Memory
onMemoryWarning
TIP
The API usage is as follows: wx.onMemoryWarning(function listener)
Functional description: Listen for low memory warning events. This event is triggered when iOS/Android issues a memory warning to the Mini Program process. Triggering this event does not mean that the Mini Program process is cleared. In most cases, it is just a warning. Developers can recycle some unnecessary resources after receiving the notification to avoid further aggravating memory shortages.
Parameters and descriptions: function listener,Listener function for low memory warning event
Properties Type Description level number Memory warning level, only available on Android, corresponding to system macro definition level legal value
Legal value Description 5 TRIM_MEMORY_RUNNING_MODERATE 10 TRIM_MEMORY_RUNNING_LOW 15 TRIM_MEMORY_RUNNING_CRITICAL Sample code:
wx.onMemoryWarning(function () {
console.log('onMemoryWarningReceive')
})offMemoryWarning
TIP
The API usage is as follows: wx.offMemoryWarning(function listener)
Functional description: Remove the listener function for low memory warning events
Parameters and descriptions: function listener,Listener function passed in by onMemoryWarning. If this parameter is not passed, all listeners will be removed
Sample code:
const listener = function (res) { console.log(res) }
wx.onMemoryWarning(listener)
wx.offMemoryWarning(listener) // Pass the same function object used for listening.