lightbulb_outline Help shape the future of the Google Play Console, Android Studio, and Firebase. Start survey

Allocation Tracker

This tool was removed in Android Studio 3.0.

You should get the latest version of Android Studio and use the new Memory Profiler instead.

Android Monitor allows you to track memory allocation as it monitors memory use. Tracking memory allocation allows you to monitor where objects are being allocated when you perform certain actions. Knowing these allocations enables you to adjust the method calls related to those actions to optimize app performance and memory use.

The Allocation Tracker does the following:

  • Shows when and where your code allocates object types, their size, allocating thread, and stack traces.
  • Helps recognize memory churn through recurring allocation/deallocation patterns.
  • Helps you track down memory leaks when used in combination with the HPROF Viewer. For example, if you see a bitmap object resident on the heap, you can find its allocation location with Allocation Tracker.

However, it takes time and experience to learn to interpret the output from this tool.

Understanding the Allocation Tracker display

The Allocation Tracker looks similar to the following figure:

The tool displays the following information:

Column Description
Method The Java method responsible for the allocation.
Count Total number of instances allocated.
Size The total amount of allocated memory in bytes.

Taking and displaying a snapshot of allocation data

To examine allocation data:

  1. Display a running app in the Memory Monitor.
  2. Click Start Allocation Tracking Start Allocation Tracking icon.
  3. Click Start Allocation Tracking Start Allocation Tracking icon again to deselect it and end the snapshot.
  4. The Memory Monitor displays the period when it took the snapshot. In the following figure, you can see the snapshot period, as shown on the left. By comparison, when you dump the Java heap, the Memory Monitor displays just the point where the heap snapshot was taken, as shown on the right.

    Android Studio creates the heap snapshot file with the filename package_yyyy.mm.dd_hh.mm.ss.alloc using the activity package (or project) name, year, month, day, hour, minute, and second of the capture, for example, com.android.calc_2015.11.17_14.58.48.alloc.

    The Allocation Tracker appears.

  5. Optionally click the graphic icon graphic icon to display a visual representation of the data.
  6. Select the Group By menu option you want to display:
    • Group by Allocator
    • Group by Method

Viewing a saved allocation tracking file

After you capture allocation data, Android Studio automatically stores it so you can view it again.

To view an allocation tracking file in the Allocation Tracker:

  1. Click Captures icon in the main window.
  2. Or select View > Tools Windows > Captures.

    The Captures window appears.

  3. Open the Allocation Tracking folder.
  4. Double-click the file to view it.

Sorting allocation data

To sort allocation data:

  • In the Allocation Tracker, click a column heading to sort the table by ascending or descending order.

Displaying Java source

For some items displayed in the Allocation Tracker, you can view the Java source.

To display Java source:

  • In the Allocation Tracker, right-click a method and then select Jump to Source.
  • In the Allocation Tracker, select a method and then click Jump to Source Jump to Source icon.

The source code appears in the Code Editor.

Working with allocation tracking files

You can rename, locate, and delete an allocation tracking file from within Android Studio.

Renaming an allocation tracking file

If you rename a file from within Android Studio, it continues to appear in the Captures window.

To rename an allocation tracking file:

  1. In the Captures window, right-click the file and select Rename.
  2. In the Rename dialog, specify the name of the file and click OK.

Locating an allocation tracking file

You can quickly discover where Android Studio stored allocation tracking files on disk.

To locate an allocation tracking file from Android Studio:

  • In the Captures window, right-click allocation file and select Show or Reveal.
  • Android Studio opens an operating system file browser displaying the location where the file resides.

Note: If you move an allocation tracking file, Android Studio no longer displays it in the Captures window. To display the file, use File > Open. Also, rename the file from the Captures window and not in the operating system file browser.

Deleting an allocation tracking file

To delete an allocation tracking file:

  • In the Captures window, right-click an allocation tracking file and select Delete.
  • Android Studio deletes the file from the Captures dialog and from disk.