Skip Headers
Oracle® Java Micro Edition Software Development Kit Developer's Guide
Release 8 for Windows
E50624-01
  Go To Table Of Contents
Contents

Previous
Previous
 
Next
Next
 

12 Memory Monitoring and Runtime Tracing

This chapter describes how to use tracing and the Memory Monitor to examine an application's memory use on a particular device.

Activating tracing for a particular device enables you to see low-level information as an application runs.

The Memory Monitor shows memory use as an application runs. It displays a dynamic detailed listing of the memory usage per object in table form, and a graphical representation of the memory use over time. You can take a snapshot of the memory monitor data. Snapshots can be loaded and examined later.


Note:

The memory usage that you observe with the emulator is not the same as the memory usage on an external device. Remember, the emulator does not represent an external device. It is one possible implementation of its supported APIs.


Enabling Tracing

To enable tracing:

  1. In the Device Selector window, right-click a device and select Properties.

  2. In the device's Properties window, expand the Monitor node and select the desired trace options:

    • Trace GC: Monitoring garbage collection can help you determine object health. The garbage collector cannot delete objects that do not have a null reference. Null objects will be garbage collected and not reported as active.

    • Trace Class Loading: Observing class initialization and loading is useful for determining dependencies among classes.

    • Trace Exceptions: Displaying exceptions caught by the Java ME SDK can be used for debugging.

    • Trace Method Calls: Reporting called and returned methods is useful to understand the operational sequence of the application. The output for this option is very verbose, and it can affect performance.

  3. (Optional) Verbose tracing output might cause you to run out of memory on the device before the application is fully tested. To increase the device memory, right-click a device and select Properties, expand the General node, and then specify the value for the Heapsize option.

To display tracing data, in the emulator, open the View menu and select Device Log when an application is running. Each device (or emulator) instance writes its own log to the device.log file in the device's configuration directory. For example, the EmbeddedDevice1 log is located in userdir\javame-sdk\8.0\work\EmbeddedDevice1\device.log

Using the Memory Monitor

To examine an application's memory usage:

  1. In the Projects view, right-click the project and select Profile.

    If the profiler is not yet integrated, you are prompted to enable profiling for the project. Click Yes to continue.

  2. Select Memory Monitor, and click Run.

    The Memory Monitor tab opens in the main working area of NetBeans IDE.

The top part of the Memory Monitor tab contains a graph, while the bottom part of the tab contains an object table. To the left of the graph is the current memory usage in bytes. The green line plots these values. The red line is the maximum amount of memory used since program execution, corresponding to the maximum size in bytes on the left.

Beneath the object table you see counters that display the total number of objects, the amount of memory used, the amount of free memory, and the total amount of memory on the device.

Click a column header in the object table to sort the data. Sorting is case sensitive.

Click a row to display the call stack tree in a window to the right of the table.

Click a folder to browse the call stack tree to see the methods that created the object.

To find a particular method in the call stack tree, click Find and enter a search string.

Click Refresh to update the call stack tree as data is gathered. It is not refreshed automatically.

Because the data changes rapidly, it is convenient to take several snapshots of the memory monitor data and review them later. Open the File menu and select Save As, then specify an MMS (memory monitor snapshot) file name and location for the monitor data snapshot.

When you exit an IMlet, object table data is cleared, but graph data is not cleared. The graph data you see is cumulative for this emulator session. The Memory Monitor plots session data for any IMlet run on the current emulator until you exit the application and close the emulator.

Viewing a Session Snapshot

To load a memory monitor snapshot.

  1. Open the File menu and select Open File.

  2. Browse to find the MMS file you saved.

    The Memory Monitor opens in its own tab in the main window. Note that the tab displays the time when the snapshot was saved.