Responding to low memory conditions

Low memory conditions occur when the user has many, memory intensive applications open and running in the background. Alternatively, if applications do not suspend processes when moved to the background they might hold memory unnecessarily

When the system runs low on memory, the BlackBerry Tablet OS tries to reclaim resources by closing background applications. The OS tries to close the application that been in the background the longest, and continues to close applications until it reclaims enough memory for normal system operation.

When the OS tries to terminate an application due to low memory, it terminates the application's processes and destroys the associated NativeApplication instance. However, the application window remains in the list of background applications. From the user's perspective, the application appears to be running in the background. When the user returns the application to the foreground, the OS restarts the application and creates an instance of NativeApplication.

When the system runs low on memory, the QNXApplication class dispatches the QNXApplicationEvent.LOW_MEMORY event. You should create a listener to process this event. When you receive a LOW_MEMORY event, your application should save state, release resources, destroy its objects. This way the user's application data should be preserved if your application is terminated.

If your application receives focus again, the user expects to return to the application in the state it was in when it was pushed to the background. Your application should detect whether it was terminated due to low memory, then load the saved state if appropriate.

Respond to low memory conditions

  1. Import the required packages.

    import qnx.system;

  2. Set up an event listener to listen for the QNXApplicationEvent.LOW_MEMORY event.

                         QNXApplicationEvent.LOW_MEMORY, onLowMemory);

    1. Define the callback function called when a low memory event occurs.

      public function onLowMemory(event:Event):void
          trace("Warning: Memory is Low");
          // Save state
          // Release resources