跳转到相应内容

最常访问

最近访问

navigation

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:

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:

Displaying Java Source

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

To display Java source:

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:

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:

此网站会使用 Cookie 来存储您在此网站上指定的语言和显示选项偏好设置。

获取最新的 Android Developers 资讯和提示,助您在 Google Play 上取得成功。

* 必填字段

成功!

在微信上关注 Google Developers

要以浏览此网站吗?

您请求访问的是网页,但是您为此网站设置的语言偏好为

要更改您的语言偏好设置并以浏览此网站吗?如果以后您想要更改语言偏好设置,请使用每个页面底部的语言菜单。

该类需要 或更高的 API 级别

此文档已被隐藏,因为您为该文档选择的 API 级别是 。您可以使用左侧导航栏上方的选择器来更改文档的 API 级别。

要详细了解如何根据您的应用需求指定 API 级别,请参阅支持不同平台版本

Take a short survey?
Help us improve the Android developer experience. (April 2018 — Developer Survey)