test source code:
<html>
<script>
var theThing = null;
var replaceThing = function () {
var priorThing = theThing;
var unused = function () {
if (priorThing) { console.log("hi"); }
};
theThing = { longStr: new Array(10000000).join('Jerry'), //
someMethod: function () { console.log("g"); }
};
};
setInterval(replaceThing, 4000);
</script>
任务管理器里若干个chrome.exe 进程:
其中的两个代码当前Chrome加载的扩展程序:
观察到内存迅速增加:
通过比较两个heap profile,发现引起内存泄露是因为code里的closure: