What do the colours mean for detached DOM nodes in the Chrome Heap Profiler?

本小妞迷上赌 提交于 2019-12-20 18:25:41

问题


When analyzing heap snapshots using Chrome devtools, I can't seem to figure out what the colours mean when viewing Detached DOM Trees. What is the difference between red & yellow?


回答1:


There is a good explanation available here.

From the article:

Red nodes do not have direct references from JavaScript to them, but are alive because they’re part of a detached DOM tree. There may be a node in the tree referenced from JavaScript (maybe as a closure or variable) but is coincidentally preventing the entire DOM tree from being garbage collected.

Yellow nodes however do have direct references from JavaScript. Look for yellow nodes in the same detached DOM tree to locate references from your JavaScript. There should be a chain of properties leading from the DOM window to the element (e.g window.foo.bar[2].baz).




回答2:


I have not found a definitive answer, but this seems to be consistently true:

A red background indicates a detached DOM node that is referenced from a variable in a closure.

A yellow background indicates a detached DOM node that is referenced from an object's property or an array element.




回答3:


Update for 2018

When using Chrome v70.0.3538.77, I found that Nodes had no background highlight at all (yet all the documentation available still refers to it), so I asked the Chromium dev team on Twitter.

From Mathias Bynens himself, it sounds like old versions of Chrome had unhighlighted references in some cases too (although this does not apply to my newer version of Chrome):

In old versions of Chrome, an unhighlighted reference like that meant that the object didn’t have a path to the window object via JS objects, meaning it’s retained by a system object or the DOM.

He followed up with this tweet:

The colors are indeed confusing! The latest stable Chrome [Tweet sent on Nov 9th 2018; should be around Chrome v70] doesn’t show colors anymore for this reason, and instead shows icons with an explanation when you hover them.

He provided a screenshot of the new presentation format in this tweet.



来源:https://stackoverflow.com/questions/13371119/what-do-the-colours-mean-for-detached-dom-nodes-in-the-chrome-heap-profiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!