Javascript memory leak/ performance issue?
Posted
by Tom
on Stack Overflow
See other posts from Stack Overflow
or by Tom
Published on 2010-05-31T01:41:12Z
Indexed on
2010/05/31
1:42 UTC
Read the original article
Hit count: 208
I just cannot for the life of me figure out this memory leak in Internet Explorer.
insertTags
simple takes string str
and places each word within start and end tags for HTML (usually anchor tags). transliterate
is for arabic numbers, and replaces normal numbers 0-9 with a &#..n; XML identity for their arabic counterparts.
fragment = document.createDocumentFragment();
for (i = 0, e = response.verses.length; i < e; i++)
{
fragment.appendChild((function(){
p = document.createElement('p');
p.setAttribute('lang', (response.unicode) ? 'ar' : 'en');
p.innerHTML = ((response.unicode) ? (response.surah + ':' + (i+1)).transliterate() : response.surah + ':' + (i+1)) + ' ' + insertTags(response.verses[i], '<a href="#" onclick="window.popup(this);return false;" class="match">', '</a>');
try { return p } finally { p = null; }
})());
}
params[0].appendChild( fragment );
fragment = null;
I would love some links other than MSDN and about.com, because neither of them have sufficiently explained to me why my script leaks memory. I am sure this is the problem, because without it everything runs fast (but nothing displays).
I've read that doing a lot of DOM manipulations can be dangerous, but the for loops a max of 286 times (# of verses in surah 2, the longest surah in the Qur'an).
© Stack Overflow or respective owner