1 Reply Latest reply on Apr 24, 2007 7:53 PM by Shane Bryzak

    Seam Remoting - JavaScript memory useage problem?

    Joshua Davis Expert

      I've notice that Firefox causes my machine to thrash when I leave a page that has Seam Remoting JavaScript running for a long period of time (say, 12 hours). I read ( http://www.jackslocum.com/blog/2006/10/02/3-easy-steps-to-avoid-javascript-memory-leaks ) that it is a good idea to set XMLHttpRequest onreadystatechange handlers to null when you are done with them, but it looks like remote.js doesn't do this.

      The sendAjaxRequest function sets onreadystate change here:

      Seam.Remoting.sendAjaxRequest = function(envelope, path, callback, silent)
      {
       Seam.Remoting.log("Request packet:\n" + envelope);
      
       if (!silent)
       Seam.Remoting.displayLoadingMessage();
      
       var asyncReq;
      
       if (window.XMLHttpRequest)
       {
       asyncReq = new XMLHttpRequest();
       if (asyncReq.overrideMimeType)
       asyncReq.overrideMimeType('text/xml');
       }
       else
       asyncReq = new ActiveXObject("Microsoft.XMLHTTP");
      
       asyncReq.onreadystatechange = function() {Seam.Remoting.requestCallback(asyncReq, callback); }
       asyncReq.open("POST", Seam.Remoting.resourcePath + path, true);
       asyncReq.send(envelope);
       return asyncReq;
      }


      but it is not set to null here:
      Seam.Remoting.requestCallback = function(req, callback)
      {
       if (req.readyState == 4)
       {
       Seam.Remoting.hideLoadingMessage();
      
       if (req.status == 200)
       {
       Seam.Remoting.log("Response packet:\n" + req.responseText);
      
       if (callback)
       callback(req.responseXML);
       }
       else
       alert("There was an error processing your request. Error code: " + req.status);
       }
      }
      


      Do you think that maybe setting onreadystatechange to null would help with this memory problem?