Troubleshooting guide

116
BlackBerry Java Development Environment Development Guide
Use the LMM
Free persistent objects
A low number of persistent object handles
exist on a BlackBerry device.
The number of persistent object handles falls below 1000.
A low number of object handles exist on a
BlackBerry device.
The number of object handles falls below 1000.
Task Steps
Register your application with the LMM. 1. In the application, implement the LowMemoryListener method.
2. Enable the application to register the LowMemoryListener with the LMM when the
application starts for the first time. Register the listener only once.
Manage events that the
LowMemoryListener receives.
> Implement the freeStaleObject(int) method of the LowMemoryListener interface.
The implementation of freeStaleObject() method should return true if persistent data is
released, or return false otherwise.
Manage low priority events. The LMM seldom specifies a priority higher than low priority.
>In an implementation of freeStaleObject(), enable the application to release transitory
variables and any variables that are currently not necessary for complete functionality, such
as cached data.
Manage medium priority events. > In an implementation of freeStaleObject(), enable the application to remove stale data,
such as very old email messages or old calendar appointments.
Manage high priority events. > In an implementation of freeStaleObject(), enable the application to remove objects in
the application on a Least Recently Used basis, removing all stale objects.
Free resources manually. The BlackBerry® device system invokes the implementation of freeStaleObject(int) when
device memory is low. To manually free resources, perform the following actions:
1. Invoke freeStaleObject(int) from the application.
2. Invoke LowMemoryManager.Poll.
Task Steps
Remove references to the object. 1. In the application, remove references to the persistent object.
2. Delete the object from its data structure.
Inform the JVM that it can now remove the
object.
> In an implementation of freeStaleObject(), invoke
LowMemoryManager.markAsRecoverable().
Commit changes to data collections. > In an implementation of freeStaleObject(), invoke PersistentObject.commit().
Condition Description