Locating memory allocation problems

Memory allocation problems can cause the BlackBerry® Java® Virtual Machine to run out of flash memory, and the BlackBerry device to reset.

Viewing memory statistics

You can use the Memory Statistics tool with the Objects tool to find memory allocation problems. The Memory Statistics tool retrieves information about the memory usage of your application, and identifies the number of objects stored in memory. The Objects tool displays detailed information about each object.

Column

Description

# objects

number of objects that are currently stored in memory

Bytes in use

amount of memory that is used by objects

Allocated

total amount of memory that is allocated to the Java® Virtual Machine

Free

amount of memory that is available

Row

Description

Object handles

number of object handles that are stored in memory

RAM

RAM usage

Flash

sum of the objects that are stored in flash memory

Transient objects (flash)

number of transient objects that are stored in flash memory

Persistent objects (flash)

number of persistent objects that are stored in flash memory

Code modules (flash)

number of code modules that are stored in flash memory

Back To Top

View statistics to locate memory allocation problems

  1. On the Window menu, click Show View > Other.
  2. Expand the BlackBerry folder.
  3. Click BlackBerry Memory Statistics View.
  4. Click OK.
Back To Top

Display objects that are stored in memory to locate memory allocation problems

  1. Specify two or more breakpoints in your code.
  2. On the Run menu, click Debug As > BlackBerry Simulator. The application runs to the first breakpoint.
  3. In the Debug view, click Suspend.
  4. On the Window menu, click Show View > Other.
  5. Expand the BlackBerry folder.
  6. Click BlackBerry Objects View.
  7. Click OK.
  8. In the BlackBerry Objects View, click Set up filters.
  9. In the Objects View Options dialog box, in the Snapshot Filter drop-down list, click Compare to Snapshot.
  10. Click OK.
  11. In the BlackBerry Objects View, click Perform garbage collection.
  12. Click Snapshot.
  13. Press F8 to resume running the application.
  14. Perform operations in the application that do not increase the number of reachable objects. For example, create a new contact and then delete it.
  15. In the Debug view, click Suspend.
  16. In the BlackBerry Objects View, click Perform garbage collection. The BlackBerry Objects View displays the number of objects that have been deleted and added since the previous snapshot. If the number of objects added is not the same as the number of objects deleted, you might have a memory allocation problem.
  17. To identify new objects, use the Type, Process, and Location filter types in the Objects View Options dialog box.
  18. To save the contents of the BlackBerry Objects View to a comma-separated values (.csv) file, click Save.
Back To Top

Find a memory allocation problem

  1. Specify two or more breakpoints in your code.
  2. On the Run menu, click Debug As > BlackBerry Simulator. The application runs to the first breakpoint.
  3. On the Window menu, click Show View > Other.
  4. Expand the BlackBerry folder.
  5. Click BlackBerry Memory Statistics View.
  6. Click OK.
  7. In the BlackBerry Memory Statistics View, click Refresh .
  8. Click Snapshot.
  9. Press F8 to resume running the application. The application runs to the second breakpoint.
  10. Click Refresh.
  11. Click Compare.
  12. Repeat steps 1 through 11, setting breakpoints closer together until they converge on the memory allocation problem.
Back To Top

Was this information helpful? Send us your comments.