Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript memory leak/ performance issue?
    text
    copied!<p>I just cannot for the life of me figure out this memory leak in Internet Explorer. </p> <p><code>insertTags</code> simple takes string <code>str</code> and places each word within start and end tags for HTML (usually anchor tags). <code>transliterate</code> is for arabic numbers, and replaces normal numbers 0-9 with a &amp;#..n; XML identity for their arabic counterparts.</p> <pre><code>fragment = document.createDocumentFragment(); for (i = 0, e = response.verses.length; i &lt; 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], '&lt;a href="#" onclick="window.popup(this);return false;" class="match"&gt;', '&lt;/a&gt;'); try { return p } finally { p = null; } })()); } params[0].appendChild( fragment ); fragment = null; </code></pre> <p>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).</p> <p>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).</p> <p><strong>* Memory leaks in IE7 and IE8, not sure about 6, but works perfectly fine in Safari 4, FF 3.6, Opera 10.5, Chrome 5... *</strong></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload