Memory management issues in JS / AJAX

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Vu
    New Member
    • Jan 2011
    • 2

    #1

    Memory management issues in JS / AJAX

    The Javascript in my web page (updated using AJAX) is causing symptoms like memory leaks on client machines. The memory usage continues to rise until the browser freezes. I have isolated it to the bit of code shown below. Does anything here stand out as a reason fom memory not to be released? Many thanks in advance.

    Code:
    function ajaxLoaderVWSF(url) {
      if (document.getElementById) {
        var x = (window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest(url);
      }
      if (x) { // got something back
        x.onreadystatechange = function() {
    
                      
                                  //main fuction goes here
    
    
                                           } 
        x.open("GET", url, true);
        x.send(null);
    
    
        if ( (maxupdates == 0) || (updates < maxupdates-1)) {
          setTimeout("ajaxLoaderVWSF(flashFile + '?' + new Date().getTime())", reloadTime);
        
            }
      }
    
    }
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Depending on how often that function is called, you're constantly creating new ActiveXObjects without freeing them.

    Comment

    • Bob Vu
      New Member
      • Jan 2011
      • 2

      #3
      Can you suggest a method to free them? I tried setting x to null, deleting x, various other things without success.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        After some research, it looks like you are unable to free up the memory because you've created a closure by assigning a reference to a function.

        This page has a lot of different ways of dealing with closures: http://jibbering.com/faq/notes/closures/#clClose.

        Comment

        • Samishii23
          New Member
          • Sep 2009
          • 246

          #5
          Not to not answer the question... But jQuery could make the coding easier for you, and they probably already accounted for this stuff.

          Comment

          Working...