does setInterval require a lot of resources?

You must Login before you can answer or comment on any questions.

How are timers implemented? If I have 4-5 timers running in parallel doing various things in my app is it a concern? are they resource intensive?

— asked 8 months ago by Ryan popa
0 Comments

1 Answer

Accepted Answer

I have not profiled the setInterval function, but I asume that the memory and CPU footprint shouldn't be much. Nevertheless, setInterval and setTimeout are both referenced in the global scope, so any data or UI object referenced by the callback will stay in memory until the interval is removed. You need to plug the callbacks against memory leaks.

— answered 8 months ago by Richard Lustemberg
answer permalink
3 Comments
  • is there any good practice regarding this or do I have to set my object references to null?

    — commented 8 months ago by Ryan popa

  • Just wondering...I would understand why you would need to clear out an interval to remove it from global scope, but does this also apply to a timeout? My instinct would be that once the timeout runs it will be cleaned up. Is that really the case?

    — commented 8 months ago by Michael Belkin

  • In principle the setTimeout() of cours fires and disipates from memory through garbage collection, although not long ago there was a bug in one of the sdk's where the native objects where not cleaned up.

    — commented 8 months ago by Richard Lustemberg

Your Answer

Think you can help? Login to answer this question!