has.onMemoryWarning(function callback)
Enables listening for low memory alarms.
Since: 1.0.16
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | Yes | Callback used to return an event indicating low memory conditions. This event serves as an early warning and does not indicate that the atomic service will be interrupted. Upon receiving this callback, you should release unnecessary resources to prevent potential memory exhaustion. |
Return value of callback
| Parameter | Type | Description |
|---|---|---|
| level | number | Memory alarm level. Value options: 5: Available system memory is moderate. 10: Available system memory is low. 15: Available system memory is critically low. |
Example:
has.onMemoryWarning(function(res) {
console.info('onMemoryWarning callback triggered', res.level);
}) has.offMemoryWarning(function callback)
Removes the listener function for low memory alarms.
Since: 1.0.16
Parameters
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | function | No | Listener function passed by has.onMemoryWarning. If this parameter is not passed, all listener functions will be removed. |
Example:
const onMemoryWarningFn = function(res) {
console.info('onMemoryWarning callback triggered', res.level);
}
has.onMemoryWarning(onMemoryWarningFn);
has.offMemoryWarning(onMemoryWarningFn); // Ensure that the callback is the same as that passed in has.onMemoryWarning.