performance - Javascript variables and memory leaking? -


is possible create memory leaks when coding in javascript? , if dependent on javascript rendering engine e.g. v8 or ie's chakra

i seem getting slow performance when iterating through large loop constructs.

should "delete" variables im not using?

var myvar = 'very long string'; delete myvar; 

in example you've shown, unless myvar in global scope garbage collected @ end of function.

in general, don't need worry memory in javascript. need worry memory when unintentionally create references objects , forget them. example:

function buttonclick() {     var clicked = false;     document.body.addeventlistener('click', function(event) {         if (clicked) return;         if (event.target.nodename !== 'button') return;         clicked = foo();     }, true); } 

the above code bad code begin (not cleaning event listeners), illustrates example of "memory leak" in javascript. when buttonclick() called, binds function click event on <body>. because removeeventlistener never called unbind listener, memory used function never reclaimed. means every time buttonclick() called, little bit of memory "leak".

even then, however, amount of memory leaked quite small , won't ever become problem vast majority of use cases. problem in server-side javascript, code potentially run more , process stays alive longer.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -