Search code examples
javascriptsetinterval

Does a timer created with `setInterval` have to be cleaned up before the window is closed?


I am making a game using Javascript, and to update the game I am using setInterval(). Should I use clearInterval() somehow on the window exit, or does it automatically stop?


Solution

  • The browser is (or better: should be) clever enough to fully clean up a closed website. That includes aborting it's running connections and terminating scripts. Data that stays on your PC after you close the tab usually only includes stuff like browser history entries, cookies, local storage and cached data (e.g. scripts, stylesheets, images).