Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does yellow background mean on object's title in Chrome's heap profiler?

Tags:

Trying to get my head around the heap profiler in Chrome Developer Tools. I see several reachable objects in the snapshot, some of them have yellow background and some not. What does it mean? What's the difference?

Color legend is not exactly helpful in this case, since it has a yellow background itself (wtf).

Heap Snapshot

like image 977
jayarjo Avatar asked Mar 13 '13 19:03

jayarjo


People also ask

What is heap memory in Chrome?

Google Chrome heap snapshot will reveal memory distribution between JavaScript objects and associated DOM nodes. This feature is useful because you will be able to compare different snapshots and find memory leak.

How do I check my chrome heap memory?

As the name implies, heap snapshots show you how memory is distributed among your page's JS objects and DOM nodes at the point of time of the snapshot. To create a snapshot, open DevTools and go to the Profiles panel, select the Take Heap Snapshot radio button, and then press the Take Snapshot button.

How do I view a memory snapshot in Chrome?

Snapshots are initially stored in the renderer process memory. They are transferred to the DevTools on demand, when you click on the snapshot icon to view it.

What is shallow size and retained size in Chrome?

Shallow and retained size This gives rise to a distinction between two ways to look at the size of an object: shallow size: the size of the object itself. retained size: the size of the object itself, plus the size of other objects that are kept alive by this object.


1 Answers

Ok, turns out yellow background means that the object that has it has a JavaScript handle on it, or so to say is accessible from the JavaScript, while object with no background (or white) is not accessible from JavaScript, but can still be reached from the root of the graph.

The most interesting though seems to be an object with red background. Red background means that the object that has it is part of detached DOM tree. So it is basically a DOM element that is not reachable from the root node, but is referenced by some other object that on it's turn is accessible from JavaScript (has yellow background that is).

Short quote from great write-up by Addy Osmani:

Q: I noticed a number of DOM nodes in the heap snapshot where some are highlighted in red and indicated as a "Detached DOM tree" whilst others are yellow. What does this mean?

You'll notice nodes of a few different colors. Red nodes do not have direct references to JavaScript from 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 to 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).

like image 101
jayarjo Avatar answered Sep 24 '22 01:09

jayarjo