Resources | Resources |



Unloading applications

If no applications have registered for the low RAM or critical low RAM notification, or, if after sending the notifications, the amount of memory freed by the registered applications is not sufficient, Brew MP will attempt to free up additional heap on its own by unloading applications in the application stack.

Brew MP starts with the first suspended application that is below the currently top-visible application and works its way down the stack. It unloads the first application from memory (an EVT_APP_STOP event is sent to the application); however, the application history stack entry for this application is left untouched. This allows Brew MP to restart the application automatically when the currently top-visible application quits.

After unloading one application, Brew MP checks the available free memory again. If there is enough to satisfy the request, Brew MP returns successfully. If there is still not enough memory, Brew MP unloads the next application in the stack, checks memory again, and continues until it has freed enough memory to satisfy the request. If, after unloading all applications (except the top-visible application), there is still not enough memory, Brew MP will return NULL for the request.

The stack for background applications is left untouched in this entire process. When the top-visible application exits, Brew MP reloads the suspended application that it first unloaded and sends the application a resume event. The resumed application can retrieve any data that it saved in the application history stack at this time, since Brew MP preserved the AppHistory entry when the application was unloaded.

Brew MP provides a mechanism to ensure that no applications are unloaded.

  1. In order for a _LOW_RAM_CRITICAL handler to prevent application unloading, it must re-register itself each time it is called.
  2. The persistent and continuous presence of the _LOW_RAM_CRITICAL handler is necessary to prevent application unloading.
  3. _LOW_RAM_CRITICAL preempts application unloading and should not be installed unless the intention is to give up application unloading.