4 ms·
Maybe I'm missing something, but the function doesn't point to `el`. `el` just exists in a lower execution context on the stack. If a variable inside the anonym
by schristo 15y ago
Maybe I'm missing something, but the function doesn't point to `el`. `el` just exists in a lower execution context on the stack. If a variable inside the anonymous function referenced `el` directly, then a closure would be formed over `el`. In this instance `this` is just assigned when the function is called.
- mattmanser 15y agoI'm not sure whether you're saying the code is wrong or you can't understand how that code creates the circular reference. This problem was widely known and stopped being a problem in IE8 I believe. Maybe it was IE7. A while ago anyway. That code looks like the type of circular reference that would cause it. You used to be able to download tools to watch for the memory leak. From what I remember the closure will keep a reference to el even though it will never use it, which means el won't be garbage collected when removed from the dom, which means the closure won't be removed from the onclick to free up el. Hence a circular reference. IE6's javascript garbage collector couldn't detect that. The article is old. Here's an article from MS in 2005 describing the problem in more detail: http://msdn.microsoft.com/en-us/library/Bb250448 http://msdn.microsoft.com/en-us/library/Bb250448 Apologies if you understood that and were just saying the code is wrong, but it looks right to me. Not that I can be bothered to fire up IE6 to test it out. EDIT: Some more detail about the definitely historical leak from SO, it also turns out it was only partially fixed in IE7: http://stackoverflow.com/questions/1999840/javascript-circular-references-and-memory-leaks http://stackoverflow.com/questions/1999840/javascript-circul...
- Roboprog 15y agoThanks for the info. So it was the dreaded IE 6 that would not release things when you reloaded or went to another page. I was wondering why the base article here said you had to restart the browser completely, as I could think of no reason to carry over objects between pages (outside of browser/external persistence). At least IE 7 implemented the obvious "clean up between pages" operation. Die, Explorer, die! :-)