目录

UI Component Memory Analysis: ComMemory

Function Description

Since DevEco Studio 6.1.1 Beta1, the ComMemory template has been added to DevEco Profiler for analyzing memory allocation of UI components, helping locate UI component memory leaks.

The ComMemory template supports the following lanes: Memory, ArkUI Snapshot, ArkTS Snapshot, All Heap & Anonymous VM, All Heap, All Anonymous VM, System Resources, and Graphic Memory. This section describes the ArkUI Snapshot lane. For details about other lanes, see the corresponding template.

Before analysis, create a ComMemory analysis task and capture related data. For details, see In-depth Capture for Problem Locating. Alternatively, click Open File in the session area and import historical data.

Viewing the Component Tree and Component Information

  1. After the capture starts, observe the memory usage in the Memory lane. Click in the upper-left corner of the task to start a snapshot when necessary. Once the snapshot is complete, a purple block appears in the ArkUI Snapshot lane.

    The Details panel displays the details of the current snapshot. Click Open to open the corresponding .arkli file in ArkUI Inspector.

  2. View the component tree in ArkUI Inspector. Show Free-Node Components is available since version 26.0.0.

    Show Component Size and Show Free-Node Components are selected by default. Show Component Size displays the memory usage of each component. Show Free-Node Components displays free-node components (components not in the component tree). Click and select Show Recursive Size to display the memory usage of subtrees rooted at each component.

  3. View component information in ArkUI Inspector.

    • In ArkUI Inspector, choose Memory > Statistics to view the memory statistics of components.
      • Current: ArkTS memory and native memory usage of the current component.
      • ArkTS: retained size of the ArkTS heap snapshot object corresponding to the current component.
      • Native: native memory usage of the current component.
      • Subtree: total current memory usage of the current component and its child components.
      • nativeCount: number of currently alive native memory allocations for the current component.
      • arktsCount: number of ArkTS heap snapshot objects for the current component.
      • recursive: recursive statistics.

    • In ArkUI Inspector, choose Memory > Details. Click any item in Details to open DevEco Profiler and view the component details.
      • ShowAllocationDetail: displays the allocation details for the current component.
      • ShowSnapshotDetail: displays the snapshot details for the current component. This option is not available for system components.
      • ShowRecursiveAllocationDetail: displays the allocation details for the current component and its child components.
      • ShowRecursiveSnapshotDetail: displays the snapshot details for the current component and its child components.

    • In ArkUI Inspector, choose Memory > States to view the state variable memory of UI components.

      The memory field indicates the retained size of the state variable in the ArkTS heap snapshot of the corresponding component. For details, see Viewing State Variables of UI Components.

  4. In the middle pane, click to export the component tree snapshot containing memory information to local storage.

Comparing .arkli Files

Since version 26.0.0, .arkli files can be compared to quickly identify components with an abnormal increase in count.

  1. After the capture starts, observe the memory usage in the Memory lane. Click in the upper-left corner of the task to start a snapshot when necessary. Once the snapshot is complete, a purple block appears in the ArkUI Snapshot lane.

    The Details panel displays the details of the current snapshot. Click Open to open the corresponding .arkli file in ArkUI Inspector.

  2. The currently opened .arkli file serves as the base file. Select another .arkli file from the Component Tree drop-down list as the target file for comparison. The comparison results include added components (in green, for example, Column), deleted components (in red, for example, NavBar), free-node components (in gray, for example, JsView), the count of added child components (in green, for example, +1576), and the count of deleted child components (in red, for example, -8). Click a component with an abnormal increase in count. The right-side Attributes panel shows the code file where the component resides; click to jump to the specific code.

    The target file must first be opened in ArkUI Inspector by clicking Open. Otherwise, it will not appear in the drop-down list.