Note that there are some explanatory texts on larger screens.

plurals
  1. POQuestions about memory leak JS (try/catch, images in b64, ajax, unset variable, removeChild)
    text
    copied!<p>OK, i have a list with a few things that makes think that is the reason why my add-on is using a lot of memory.</p> <p>1 - Use try/catch can increase memory usage? Example:</p> <pre><code>try{ if(!condition) throw "Message"; //some code }catch(ex){} </code></pre> <p>If this is the problem,I was thinking in use:</p> <pre><code>(function(){ if(!condition) return; })(); </code></pre> <p>2 - Use images with base64 can improve memory usage too?</p> <pre><code>&lt;img src="data:image/png;base64,[...]==" /&gt; </code></pre> <p>Or there is no problem?</p> <p>3 - I use a function to handle ajax result, so i can use responseXML...</p> <pre><code>if (o.readyState != 4) return; var newdoc = document.implementation.createDocument(null, null, null); var newhtml = document.createElement('div'); newhtml.innerHTML = o.responseText.replace(/script/ig, ""); newdoc.appendChild(newhtml); newdoc.getElementById('...'); </code></pre> <p>I cannot use jquery, this is the easiest way that I found to use responseXML, but may causing memory leak too.</p> <p>4 - Unset variables, helps in something or is unhelpful?</p> <pre><code>var a = "something"; if(a=="something") // //I'm not going to use the variable "a" anymore, so.. a = undefined; //Now i unset the variable </code></pre> <p>5 - If you add an Event to a element, or you use appenChild, this increases memory.</p> <pre><code>element.appendChild(newelement); </code></pre> <p>If you change the page, looks like the memory is still the same.. If I use </p> <pre><code>window.addEventListener("unload", function() { element.removeChild(newelement) } </code></pre> <p>This helps in something too?</p> <p>Thanks.</p> <p>Sorry for the english.</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