Skip to content

Instantly share code, notes, and snippets.

@leeoniya
Created August 5, 2017 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leeoniya/2819457aced978460c7a1c471a6d3c74 to your computer and use it in GitHub Desktop.
Save leeoniya/2819457aced978460c7a1c471a6d3c74 to your computer and use it in GitHub Desktop.
<!doctype html>
<html>
<head>
<script src="https://cdn.rawgit.com/leeoniya/domvm/3.x-dev/dist/nano/domvm.nano.js"></script>
</head>
<body>
<script>
// http://imgur.com/a/YATqh
// https://cdn.rawgit.com/leeoniya/6149d983cd128ca6ac7c06e9dd3bd80f/raw/fe86cef4cc97aad1b89ef685643afa8590763a66/domvm-memleak.html
var el = domvm.defineElement;
function ListView() {
return (vm, list) =>
el("ul", list.map(item =>
el("li", item.val)
));
}
function randInt(min, max) {
return Math.floor(Math.random()*(max-min+1)+min);
}
function randColor() {
return '#'+Math.floor(Math.random()*16777215).toString(16);
}
function makeList(qty) {
var items = [];
while (qty--)
items.push({val: randColor()});
return items;
}
// run for 60 secs @ 100ms redraws
var iter = 600;
/* // leaks
setTimeout(function() {
var vm = domvm.createView(ListView, makeList(100)).mount(document.body);
var i = 0;
var it = setInterval(function() {
vm.update(makeList(randInt(0, 100)));
if (iter-- == 0)
clearInterval(it);
}, 100);
}, 1000);
*/
// no leaks
setTimeout(function() {
var vm = domvm.createView(ListView, makeList(100)).mount(document.body);
var i = 0;
var it = setInterval(function() {
vm.update(makeList(100));
if (iter-- == 0)
clearInterval(it);
}, 100);
}, 1000);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment