I'm struggling to pinpoint the memory leak issue in Internet Explorer.
insertTags
takes a string str
and wraps each word in HTML start and end tags (usually anchor tags). Meanwhile, transliterate
is used for converting Arabic numbers, replacing normal numbers 0-9 with their Arabic counterparts presented as &#..n; XML identities.
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 could use some alternative resources other than MSDN and about.com for understanding my script's memory leakage issues. It's clear that this is the root cause, as everything works smoothly when it's not present (although nothing gets displayed).
I've come across warnings about potential risks of excessive DOM manipulations, but the loop only goes up to 286 times (# of verses in surah 2, the longest chapter in the Qur'an).
* Experiencing memory leaks in IE7 and IE8, unsure about IE6, yet Safari 4, FF 3.6, Opera 10.5, Chrome 5 perform perfectly well... *