clearTimeout and clearInterval: are they mandatory?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ifedi
    New Member
    • Jan 2008
    • 60

    #1

    clearTimeout and clearInterval: are they mandatory?

    Hi all,
    I have an application that uses setInterval and setTimeout in many places. In particular, most of the setInterval is used to fetch AJAX content periodically for items that may have changed in the server...
    Problem is that my browsers progressive consume the system resources as time goes on. The impression i get is that memory does not get released even with page refreshes.
    I suspect it might partly have to do with uncleared timeouts.
    My core question is: How mandatory is it to clear a setTimeout that has been set, and that has already fired?
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    it is always good practice to drop references to all unused things when you know that you don't need it anymore. basically all browsers suffer from memory leaks that could have certain reasons ... most likely from creating and/or manipulating the document's DOM ... or creating closures that will hold references to variables that aren't used anymore ... you might have a look at the following sources which address such problems:





    just to mention some of the resources that deal with that issue.

    kind regards

    Comment

    • ifedi
      New Member
      • Jan 2008
      • 60

      #3
      Thanks gits.
      I'll take a look at those links shortly.
      But I was thinking: surely, a page refresh should drop those references, shouldn't it? Therefore, since it might be the AJAX requests that are to blame here, how would you drop references where you still continue to need to watch the server for changes?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5390

        #4
        basically a page refresh clears the JavaScript-references but for example when DOM is involved and would contain circular references ... have a look here for example ... this should even apply to Mozilla's XPCOM ... then memory leaks occur

        kind regards

        Comment

        Working...