let theThing = null;
let replaceThing = function () {
let originalThing = theThing;
let unused = function () {
if (originalThing)
console.log("hi");
};
theThing = {
longStr: new Array(10000).join('*'),
someMethod: function () {
console.log(1111);
}
};
};
setInterval(replaceThing, 1000);
图片是执行代码的内存快照,我的问题是:
为什么someMethod会引用originalThing,造成内存泄漏?
这个好像是执行上下文的关系,不是相互引用的关系