Best practice: Minimizing memory use
To minimize runtime memory, consider the following guidelines:
•
Use primitive types (such as
int
or
Boolean
) instead of objects (such as
String
or
Integer
).
•
Do not depend entirely on the garbage collector.
•
Avoid creating many objects quickly.
•
Set object references to null when you are finished using them.
•
Reuse objects as much as possible.
•
Move heavy processing to the server. For example, you can filter or sort data before sending it to the BlackBerry® device.
Managing low memory availability
The low memory manager handles memory resources on the BlackBerry® device when the available memory resources fall below
a certain threshold. The low memory manager attempts to free used memory to provide more available memory on the BlackBerry
device. All applications, including BlackBerry® Java Applications, should work with the low memory manager to free as much
memory as possible when the BlackBerry device is low on memory resources.
Identifying low memory availability on a BlackBerry device
The following conditions can cause the low memory manager to attempt to free memory resources:
•
The amount of available flash memory on the BlackBerry® device falls below a certain threshold. The flash memory threshold
depends on the amount of free RAM in the system. The flash memory threshold ranges between 400 KB and 800 KB.
•
The number of persistent object handles that are available on the BlackBerry device falls below 1000 persistent object
handles.
•
The number of object handles that are available on the BlackBerry device falls below 1000 object handles.
Conserving resources
Best practice: Using efficient data structure selection
Data structure selection defines how many object handles and how much flash memory a BlackBerry® Java Application consumes.
Improper data structure selection can consume key resources without improving the BlackBerry Java Application functionality
or the BlackBerry device user experience.
Consider the following guidelines:
Fundamentals Guide
Managing low memory availability
25