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.

  1. Open Timeline tab.
  2. Start recording activty.
  3. Repeat the next steps and watch the Timeline
    1. Create some nodes
    2. 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();
}