Jump to content

does setInterval use a lot of ram/cpu if you..


shortysbest

Recommended Posts

If I have setInterval at a 1 second delay would it cause the browser/computer to use a lot more ram/cpu then if it were to be 10 seconds, or 60 seconds? Like enough that it could cause problems with somebodies computer.

Also, for loading new comments into the page as they come would it be better to use setInterval, or setTimeout and just trigger the function at the end of it so it would act the same as interval just not trigger until it has completed the query.

Link to comment
Share on other sites

If you are wanting something to be run every X seconds indefinitely, use setInterval() instead of setTimeout().  They are practically the same thing but with setInterval() you don't have to take the extra step of having your function recursively call itself. 

 

In and of itself it doesn't matter how many seconds you delay it.  What matters is what you are actually doing when the function is run.  For instance, if you are appending a new element to a global or static array, adding new content to page, etc...  each iteration, things are going to add up.  Iterating every 1s will give you 60 new elements in 1 minute, vs. 6 new elements, if you are iterating every 10s.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.