如何在时间线上使用分配检测How to use Allocation instrumentation on Timeline

日程表上使用分配 检测来查找未正确进行垃圾回收的对象,并继续保留内存。Use Allocation instrumentation on timeline to find objects that are not being properly garbage collected, and continue to retain memory.

时间线上的分配检测的工作原理How Allocation instrumentation on timeline works

时间线上的分配检测将堆探查器的详细快照信息与**** 性能面板的增量更新和跟踪相结合。Allocation instrumentation on timeline combines the detailed snapshot information of the heap profiler with the incremental updating and tracking of the Performance panel. 同样,跟踪对象的堆分配涉及启动记录、执行一系列操作以及停止记录进行分析。Similarly, tracking heap allocation for objects involves starting a recording, performing a sequence of actions, and stopping the recording for analysis.

时间线上的分配检测 在整个记录 \ (中定期获取堆快照,频率为每 50 ms) ,最后一个快照位于录制末尾。Allocation instrumentation on timeline takes heap snapshots periodically throughout the recording (as frequently as every 50 ms) and one final snapshot at the end of the recording.

日程表上的分配检测

备注

后一 @ 个数字是对象 ID,在录制会话期间获取的多个快照中保留。The number after the @ is an object ID that persists across the multiple snapshots taken during the recording session. 通过永久性对象 ID,可以在堆状态之间进行精确比较。The persistent object ID enables precise comparison between heap states. 对象在垃圾回收期间移动,因此显示对象的地址没有任何意义。Objects are moved during garbage collections, so displaying the address of an object makes no sense.

在时间线上启用分配检测Enable Allocation Instrumentation on Timeline

完成以下操作以开始在时间线上使用 Allocation instrumentation。Complete the following actions to begin using Allocation instrumentation on timeline.

  1. 打开 DevToolsOpen the DevTools.

  2. 打开内存 面板 ,选择时间线 上的分配检测单选 按钮。Open the Memory panel, select the Allocation instrumentation on timeline radio button.

  3. 开始录制。Start recording.

    记录堆分配探查器

读取堆分配时间线Read a heap allocation timeline

堆分配时间线显示对象的创建位置,并标识保留路径。The heap allocation timeline shows where objects are being created and identifies the retaining path. 在下图中,顶部的条形指示何时在堆中发现新对象。In the following figure, the bars at the top indicate when new objects are found in the heap.

每个栏的高度对应于最近分配的对象的大小,而条形的颜色指示这些对象是否仍位于最终堆快照中。The height of each bar corresponds to the size of the recently allocated objects, and the color of the bars indicate whether or not those objects are still live in the final heap snapshot. 蓝色条指示仍位于时间线末尾的对象,灰色条指示在时间线期间分配但之后已被垃圾回收的对象。Blue bars indicate objects that are still live at the end of the timeline, Gray bars indicate objects that were allocated during the timeline, but have since been garbage collected.

时间线快照上的分配检测

你能够使用上述时间线中的滑块放大该特定快照并查看此时最近分配的对象:You are able to use the sliders in the timeline above to zoom into that particular snapshot and review the objects that were recently allocated at that point:

放大快照

选择堆中的特定对象将显示堆快照底部部分的保留树。Choosing on a specific object in the heap shows the retaining tree in the bottom portion of the heap snapshot. 检查对象的保留路径应为您提供足够的信息来了解未收集对象的原因,并且应进行必要的代码更改以删除不必要的引用。Examining the retaining path to the object should give you enough information to understand why the object was not collected, and you should make the necessary code changes to remove the unnecessary reference.

按功能查看内存分配View memory allocation by function

你能够通过 JavaScript 函数查看内存分配。You are able to view memory allocation by JavaScript function. 有关详细信息,请导航到按 函数 调查内存分配For more information, navigate to Investigate memory allocation by function.

联系 Microsoft Edge DevTools 团队Getting in touch with the Microsoft Edge DevTools team

使用以下选项讨论帖子中的新功能和更改,或与 DevTools 相关的任何其他内容。Use the following options to discuss the new features and changes in the post, or anything else related to DevTools.

  • 使用“发送反馈”图标发送反馈,或在 DevTools 中选择Alt+Shift+I \ (Windows、Linux) 或 Option+Shift+I \ (macOS)。Send your feedback using the Send Feedback icon or select Alt+Shift+I (Windows, Linux) or Option+Shift+I (macOS) in DevTools.
  • 发推 @EdgeDevToolsTweet at @EdgeDevTools.
  • 我们想要的 Web 提交建议。Submit a suggestion to The Web We Want.
  • 若要提交有关本文的错误,请使用以下“反馈” 部分。To file bugs about this article, use the following Feedback section.

Microsoft Edge DevTools 中的“发送反馈”图标

备注

此页面的某些部分是根据 Google 创建和共享的作品所做的修改,并根据 Creative Commons Attribution 4.0 International License 中描述的条款使用。Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License.
原始页面位于 此处 ,由 Meggin Kearney \ (Technical Writer) 。The original page is found here and is authored by Meggin Kearney (Technical Writer).

Creative Commons License
本作品根据 Creative Commons Attribution 4.0 International License 获得许可。This work is licensed under a Creative Commons Attribution 4.0 International License.