Example 6
Example 6: Leaking DOM nodes
If the compiler can use hidden classes, your code will execute MUCH faster and will use MUCH LESS memory.
- Open Timeline tab.
- Start recording activty.
- Repeat the next steps and watch the Timeline
- Create some nodes
- GC
'use strict'; var leakedNodes = []; function createNode(text) { var div = document.createElement("div"), innerDiv = document.createElement("div"); innerDiv.appendChild(document.createTextNode(text + " - "+ new Date().toTimeString())); div.appendChild(innerDiv); return div; } function createLeakedNodes() { var i; for (i = 0; i < 20; i++) { leakedNodes.push(createNode("Leaked:" + i)); } } function createGCNodes() { var i; for (i = 0; i < 20; i++) { createNode("Collected:" + i); } } function createNodes() { createLeakedNodes(); createGCNodes(); }