假设我有一个像这样的“神奇”功能......(将解释神奇)
var arr = ['hello','I','am','in','an','array'];
(function() {
var z = document.getElementById('z');
//before edit: a = arr;
//let's leak memory... for fun!
z.onclick = function () {
var something = ...; //something, the uglier the better :P
//before edit: a.push(something);
arr.push(something);
something = null;
};
//now lets say by doing so I 'magically' fix my memory leak
//before edit: a = z = null;
z = null;
}());
但是,如果我要这样做呢...
//instead of a = z = null;
return null;
通过将 null 重新调整为我的自调用函数,是否会将所有局部变量(a、z)标记为垃圾收集,或者它们是否仍会在浏览器中具有引用并因此仍会占用内存?
注意:我正在尝试考虑 ie7 等旧版浏览器。另外,我正在“尝试”自学 JavaScript,所以这可能没有太大意义。