setTimeout memory leak

For those who use setTimeout function in Javascript - do not pass name of function you want to trigger as a sting. If used with string - Javascript will use EVAL to execute it - this is creating a memory leak if used for instant loop. Garbadge collector will not clear the memory after calling clearTimeout and delete setTimeout object. Insted of using string - use blank funtion and put funtion you want to trigger inside. This will not involve EVAL, but will generate a pointer that Garbadge collector will handle and free up memory.


// generates memory leak:
myTimeout = setTimeout(”myFunction()”, 1000);
// no memory leak (no parameters to pass):
myTimeout = setTimeout(myFunction, 1000);
// OR:
myTimeout = setTimeout(function() { myFunction(); }, 1000);

Unfortunately, all the the samples of setTimeout function out there in the internet are passing string as parameter. Hard to identify memory leak, but it is there.

Tags:

4 Responses to “setTimeout memory leak”

  1. Diana Says:

    Hello,
    Thank you for the update Ipk Combo. Maybe you can help me on another problem.
    I downloaded IE 9 and Sidebar.exe process memory keeps growing. I do not know what to do.

    I Premium 64-bit Windows Seven.

    Thank you for your help.

  2. Pavel Kuzub Says:

    Hello,
    Welcome. Another version is coming soon. As of sidebar.exe and memory growing - check About of your Internet Explorer 9 - it should state RTM or reference to newer version as part of some KB reference. If it is older version like Beta, RC, etc - then the reason for memory leak is a known issue that has been fixed in later releases of IE9. The message is to try update IE9.

    But, if you have the latest version of IE9 and memory keeps growing, then the code of gadget should be updated to handle this issue.

    In my experience, IE9 is not friendly at all to loops that are working with DOM objects.
    What are the gadgets you have that are eating the memory? If you also are runing iPK Combo 1.1 then you should wait for next update as IE9 don’t like it so far.

  3. Ross Killen Says:

    Good job. Really noticed an improvement in performance after implementing this suggestion site-wide.

  4. Smitha232 Says:

    Wow, awesome blog layout! How long have you been blogging dcdbbedkec

Leave a Reply

Spam protection by WP Captcha-Free


школа современных танцев в голосеевском районе cialis