Managing low memory
When the available memory on a BlackBerry smartphone falls below the threshold that the smartphone requires to function correctly, the Low Memory Manager attempts to make more memory available. The Low Memory Manager prioritizes objects in memory and marks the less critical objects for deletion by the BlackBerry Java Virtual Machine. Opened messages and older calendar entries are typically deleted first.
The Low Memory Manager API is implemented in net.rim.device.api.lowmemory .
You should design your app to work with the Low Memory Manager to make available as much memory as possible when the smartphone is low on memory resources. To do so, implement the LowMemoryListener interface and register it with the Low Memory Manager by calling the static LowMemoryManager.addLowMemoryListener() method.
The LowMemoryListener interface has a single method, freeStaleObject(), that is invoked by the Low Memory Manager when it needs to make memory available. When it invokes freeStaleObject(), the Low Memory Manager passes a priority parameter to indicate that it is initiating a high, medium, or low memory recovery request. Be careful to return true from freeStaleObject() if you freed any resources and false otherwise. This is important because the Low Memory Manager needs an accurate accounting of the memory freeing progress.
Identifying low memory availability
The following conditions can cause the Low Memory Manager to attempt to free memory resources:
- The amount of memory available on the smartphone falls below a certain threshold. The threshold depends on the amount of free RAM in the system. The memory threshold ranges from 400 KB to 800 KB.
- The number of persistent object handles that are available on the smartphone falls below 1000.
- The number of object handles that are available on the smartphone falls below 1000.