Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
3 contributors

Users who have contributed to this file

@dr4b @Meggin @jakub-g
97 lines (75 sloc) 1.89 KB
{{+bindTo:partials.standard_devtools_article}}
<!DOCTYPE html>
<h1>Example 6</h1>
<h1>Example 6: Leaking DOM nodes</h1>
<p>If the compiler can use hidden classes, your code will execute MUCH faster and will
use MUCH LESS memory.</p>
<ol>
<li>Open Timeline tab.</li>
<li>Start recording activty.</li>
<li>Repeat the next steps and watch the Timeline
<ol>
<li>Create some nodes</li>
<li>GC</li>
</ol>
</li>
</ol>
<p><button onclick="createNodes()">Create nodes (some of them leaked)</button></p>
<script>
'use strict';
var leakedNodes = [];
function createNode(text) {
var div = document.createElement('div'),
innerDiv = document.createElement('div'),
buf;
buf = document.createTextNode(text + ' - ' + new Date().toTimeString());
innerDiv.appendChild(buf);
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();
}
</script>
<hr>
<pre>
'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 &lt; 20; i++) {
leakedNodes.push(createNode("Leaked:" + i));
}
}
function createGCNodes() {
var i;
for (i = 0; i &lt; 20; i++) {
createNode("Collected:" + i);
}
}
function createNodes() {
createLeakedNodes();
createGCNodes();
}
</pre>
{{/partials.standard_devtools_article}}
You can’t perform that action at this time.