开发者

When does JavaScript interval stops?

It may be a naive question but I need to know the answer.

This is my code,

setInterval(function() { /do stth./}, 1000);

I never cancel the timer, I need to run it as long as user is on the page, I need to know will it case any memory 开发者_运维问答leak, or when will it stop (ie, browser refresh, browser close)?


The only problem can occur when you "do something". If you have other long running functions or even additional intervals inside the interval (a la Javascript Inception) then you could run into performace issues.

However, in almost all cases, you won't have any problems.

When the user refreshes the browser, the interval will begin anew. When the browser is closed then all activity stops.

As long as the user doesn't refresh the browser or leave the page then the interval will never end.


it stops when you leave the page. It shouldn't cause leaks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜