On Sep 28, 10:09 am, beegee <bgul...@gmail.comwrote:
On Sep 26, 9:54 pm, David Mark <dmark.cins...@gmail.comwrote:
On Sep 26, 4:26 pm, David Mark <dmark.cins...@gmail.comwrote:
Oops. Left out the memory leak cleanup.
global.onunload = function() {
i = 0;
l = anchors.length;
while (i < l) { anchors[i++].onclick = null; }
};
Goes right before this line:
el.style.visibility = 'visible';
David, thanks to your sample code post I have now lowered my self
evaluation of my javascript skills by 2 points. ;) Could you
tell me
I've lowered my own several points based on the post from late last
night. I must have been really tired when I came up with that one.
Change the correction to:
if (el && el.style) { el.style.visibility = 'visible'; }
Moving the line out a level meant that the style property was not
assured.
what memory leak you're referring to? I thought garbage collection
would pick this stuff off.
IE has a bug where closures that create circular references involving
DOM objects are not garbage collected.
http://www.jibbering.com/faq/faq_notes/closures.html
Read this line carefully and you will see that every anchor will leak
the code in its onclick event. The solution is to break the circular
references when the page is unloaded.
elPost.onclick = anchors[i].onclick = (function(posts, el) { var b;
return function(e) { e = e || global.event; b = (el.className ==
'closed'); el.className = (b)?'open':'closed'; showPosts(posts, b); if
(e.stopPropagation) { e.stopPropagation(); } e.cancelBubble = true;
return false; }; })(posts, anchors[i]);
In short, the onclick property of anchors[i] is an anonymous function
which creates a closure referencing anchors[i] as el.