背景:受这个问题以及关于D3内存使用的这个问题的启发,我决定深入了解它是如何工作的,并且很快就注意到在IE中重复添加/删除DOM节点.
为了隔离D3正在做的其他事情,我首先尝试了每秒添加/删除1000个圆圈的基本SVG案例:
var count = 1000;
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svg.setAttribute('width', '800');
svg.setAttribute('height', '800');
document.body.appendChild(svg);
function update() {
// remove existing circles
var circles = svg.querySelectorAll("circle")
for (var i = circles.length - 1; i >= 0; i--) {
var parent = circles[i].parentNode;
if (parent) parent.removeChild(circles[i]);
};
// add new ones. Yes, would make more sense to update the x,y on the existing
// circles but this is to show what happens in IE …Run Code Online (Sandbox Code Playgroud)