请简明扼要地解释上述泄漏原因,我没有理解到关键点。
function addHandler() { var el = document.getElementById('el'); el.onclick = function() { this.style.backgroundColor = 'red'; } }
The above code sets up the element to turn red when it is clicked. It also creates a memory leak. Why? Because the reference to el is inadvertently caught in the closure created for the anonymous inner function. This creates a circular reference between a JavaScript object (the function) and a native object (el).
由于泄漏,网站/页面是否面临安全问题?我该如何避免它们?还有哪些代码可能会导致内存泄漏?如何判断内存泄漏已经发生?
我是内存泄漏的绝对初学者。有人能够逐步为我澄清这个问题吗?同时,有人能帮助我澄清这句话“这在JavaScript对象(函数)和本地对象(el)之间创建了循环引用。”吗?