-
Notifications
You must be signed in to change notification settings - Fork 128
/
Copy pathexample-09.js
49 lines (41 loc) · 1.02 KB
/
example-09.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"use strict";
var leakedNodes = [],
parentDiv,
leaf,
counter = 0;
function createLeaf() {
counter++;
var div = document.createElement("div");
div.appendChild(document.createTextNode("Leaf " + counter));
div.someText = new Array(1e6).join("x");
return div;
}
function createBranch(number) {
var div = document.createElement("div");
createNodesAndReturnLastLeaf(div, number - 1);
return div;
}
function createNodesAndReturnLastLeaf(parentDiv, number) {
var i, lastLeaf;
for (i = 0; i < number; i++) {
parentDiv.appendChild(createBranch(number));
}
for (i = 0; i < number; i++) {
parentDiv.appendChild((lastLeaf = createLeaf(number, i)));
}
return lastLeaf;
}
function createTree() {
parentDiv = document.createElement("div");
leaf = createNodesAndReturnLastLeaf(parentDiv, 4);
document.body.appendChild(parentDiv);
}
function detachTree() {
document.body.removeChild(parentDiv);
}
function removeTreeReference() {
parentDiv = null;
}
function removeLeafReference() {
leaf = null;
}