我想说得到了这个:
for(var i = 0 ; i < 100000 ; i++) { // I know, this is not recommended to do it that way... // Used it because it is the easiest way to create // different functions to explain the question. a = [ new Function('return ' + i) ]; } a = 0;
创建的功能是否被删除?或者它们仍然存在但无法再访问?我可以在此代码中遇到内存问题吗?(不谈性能)
注意:我实际上并没有直接"覆盖"函数:我正在覆盖包含该函数的对象.
只要没有引用所述对象(包括函数),那么它们将被垃圾收集.
例如,标记和扫描算法遍历对象以检查潜在的"垃圾".一旦对象"无法访问"(任何代码都无法访问),它就会被标记为垃圾回收.