DWR

IE memory leak related to timeout setting

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0.1
  • Fix Version/s: 2.0.4
  • Component/s: Engine
  • Description:
    Hide
    -----Original Message-----
    From: Christofer Jennings
    Sent: den 8 juli 2007 01:08
    To: users@dwr.dev.java.net
    Subject: [dwr-user] IE memory leak related to timeout setting?

    There might be an IE memory leak in engine.js related to timeout settings.

    I've been chasing a memory leak for quite a while. After many tests, I
    think I've isolated it to setting a timeout for a DWR call. Below is
    the lines in dwr version 2.0.1's engine.js that I think look
    suspicious because of the function block / closure (lines 634 - 635).
    Below that is my jsp with a comment on the timeout line. The poll
    method returns a response object with a message property, but
    otherwise it's pretty straight forward. Attached is the Process
    Explorer memory use graph showing slopes for when the timeout is set,
    as well as no slope when timeout is not set.

    My tests were all done using IE 7 (version 7.0.5730.11) on Windows XP,
    but I've seen the (possibly) same leak in IE 6. I think they are the
    same as far as this is concerned.

    In any case, my next test will be to change the closure to a function reference.

    Does this look right? Has anyone else had trouble with timeout
    settings and IE memory leaks?

    ,chris


    #### from engine.js ######
    if (batch.timeout && batch.timeout != 0) {
      batch.interval = setInterval(function() {
    dwr.engine._abortRequest(batch); }, batch.timeout);
    }

    #### my jsp ############
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
      <title>DWR Poll Test</title>
      <script type='text/javascript' src='../dwr/interface/MyObject.js'></script>
      <script type="text/javascript">
        function doPoll()
        {
          MyObject.poll(
          {
            timeout: 2000, /* removing this line stops the leak */
            callback:function(response)
            {
              var now = new Date();
              var msg = now + "\n----------------------";
              msg += "\n message = " + response.message;
              msg += "\n----------------------\n" + now;
              dojo.byId("theTextArea").value = msg;
            }
          });
        }

        window.setInterval(doPoll, 1000);
      </script>
    </head>

    <body>
    <h2>DWR Poll Test</h2>
    <textarea id="theTextArea" rows="10" cols="60"></textarea>
    </body>
    </html>
    Show
    -----Original Message----- From: Christofer Jennings Sent: den 8 juli 2007 01:08 To: users@dwr.dev.java.net Subject: [dwr-user] IE memory leak related to timeout setting? There might be an IE memory leak in engine.js related to timeout settings. I've been chasing a memory leak for quite a while. After many tests, I think I've isolated it to setting a timeout for a DWR call. Below is the lines in dwr version 2.0.1's engine.js that I think look suspicious because of the function block / closure (lines 634 - 635). Below that is my jsp with a comment on the timeout line. The poll method returns a response object with a message property, but otherwise it's pretty straight forward. Attached is the Process Explorer memory use graph showing slopes for when the timeout is set, as well as no slope when timeout is not set. My tests were all done using IE 7 (version 7.0.5730.11) on Windows XP, but I've seen the (possibly) same leak in IE 6. I think they are the same as far as this is concerned. In any case, my next test will be to change the closure to a function reference. Does this look right? Has anyone else had trouble with timeout settings and IE memory leaks? ,chris #### from engine.js ###### if (batch.timeout && batch.timeout != 0) {   batch.interval = setInterval(function() { dwr.engine._abortRequest(batch); }, batch.timeout); } #### my jsp ############ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head>   <title>DWR Poll Test</title>   <script type='text/javascript' src='../dwr/interface/MyObject.js'></script>   <script type="text/javascript">     function doPoll()     {       MyObject.poll(       {         timeout: 2000, /* removing this line stops the leak */         callback:function(response)         {           var now = new Date();           var msg = now + "\n----------------------";           msg += "\n message = " + response.message;           msg += "\n----------------------\n" + now;           dojo.byId("theTextArea").value = msg;         }       });     }     window.setInterval(doPoll, 1000);   </script> </head> <body> <h2>DWR Poll Test</h2> <textarea id="theTextArea" rows="10" cols="60"></textarea> </body> </html>

Issue Links

Activity

Hide
Mike Wilson added a comment - 06/Mar/08 10:18 AM

----Original Message----
From: Christofer Jennings bozmoz@gmail.com
Sent: den 8 juli 2007 20:45
To: users@dwr.dev.java.net
Subject: [dwr-user] Re: IE memory leak related to timeout setting?

Using a function reference stopped the leak. It can probably be done
better, but the change I made for the test is below. The resulting
graph is attached.

        1. from modified enjine.js ######
          dwr.engine._chris_abort_batch;
          dwr.engine._chris_abortRequest = function()
          {
          dwr.engine._abortRequest(dwr.engine._chris_abort_batch);
          }

/** @private Actually send the block of data in the batch object. */
dwr.engine._sendData = function(batch) {
...
// Set a timeout
if (batch.timeout && batch.timeout != 0) {
dwr.engine._chris_abort_batch = batch;
batch.interval = setInterval(dwr.engine._chris_abortRequest, batch.timeout);
// batch.interval = setInterval(function() { dwr.engine._abortRequest(batch); }, batch.timeout);
}
...

Show
Mike Wilson added a comment - 06/Mar/08 10:18 AM ----Original Message---- From: Christofer Jennings bozmoz@gmail.com Sent: den 8 juli 2007 20:45 To: users@dwr.dev.java.net Subject: [dwr-user] Re: IE memory leak related to timeout setting? Using a function reference stopped the leak. It can probably be done better, but the change I made for the test is below. The resulting graph is attached.
        1. from modified enjine.js ###### dwr.engine._chris_abort_batch; dwr.engine._chris_abortRequest = function() { dwr.engine._abortRequest(dwr.engine._chris_abort_batch); }
/** @private Actually send the block of data in the batch object. */ dwr.engine._sendData = function(batch) { ... // Set a timeout if (batch.timeout && batch.timeout != 0) { dwr.engine._chris_abort_batch = batch; batch.interval = setInterval(dwr.engine._chris_abortRequest, batch.timeout); // batch.interval = setInterval(function() { dwr.engine._abortRequest(batch); }, batch.timeout); } ...
Hide
Mike Wilson added a comment - 06/Mar/08 10:46 AM

Actually, the issue is affecting all tested browsers (IE, Firefox and
Safari) and you are right about suspecting the abortRequest function.

My analysis shows that this is not a memory leak per se, as memory
is reclaimed when navigating to another page, but it is what I call a
memory hog as it consumes more and more memory while staying on the
page.
The cause of the problem is missing cleanup of the "abort thread" (an
interval) which is only created when using timeouts. The interval
holds on to a closure and voila there's the memory hogging. Note that
the closure is needed for abort context so your suggested fix is not
recommendable. Worth noting is that this bug may also make the browser
unresponsive after several thousand calls as abort intervals
accumulate and take cpu resources.

Show
Mike Wilson added a comment - 06/Mar/08 10:46 AM Actually, the issue is affecting all tested browsers (IE, Firefox and Safari) and you are right about suspecting the abortRequest function. My analysis shows that this is not a memory leak per se, as memory is reclaimed when navigating to another page, but it is what I call a memory hog as it consumes more and more memory while staying on the page. The cause of the problem is missing cleanup of the "abort thread" (an interval) which is only created when using timeouts. The interval holds on to a closure and voila there's the memory hogging. Note that the closure is needed for abort context so your suggested fix is not recommendable. Worth noting is that this bug may also make the browser unresponsive after several thousand calls as abort intervals accumulate and take cpu resources.
Hide
Mike Wilson added a comment - 08/Apr/08 12:50 PM

Fixed issue by changing interval to timeout.

Show
Mike Wilson added a comment - 08/Apr/08 12:50 PM Fixed issue by changing interval to timeout.
Hide
Jose Lumang added a comment - 07/May/08 6:49 PM

Hi Mike,

Where can we get the 2.0.4 version? We are also having similar issue wit our app using IE that after a while the whole app freezes.

Jay

Show
Jose Lumang added a comment - 07/May/08 6:49 PM Hi Mike, Where can we get the 2.0.4 version? We are also having similar issue wit our app using IE that after a while the whole app freezes. Jay
Hide
Mike Wilson added a comment - 08/May/08 8:19 AM
Show
Mike Wilson added a comment - 08/May/08 8:19 AM You can find a Release Candidate at https://dwr.dev.java.net/servlets/ProjectDocumentList?folderID=9081
Hide
Jose Lumang added a comment - 08/May/08 8:46 PM

Mike,

After upgrading to 2.0.4 the hanging stops.

By default is DWR setup in Passive mode.

Is there a recommended configuration?

Sorry to ask so many question i'm kinda new to DWR.

Thanks.

Jay

Show
Jose Lumang added a comment - 08/May/08 8:46 PM Mike, After upgrading to 2.0.4 the hanging stops. By default is DWR setup in Passive mode. Is there a recommended configuration? Sorry to ask so many question i'm kinda new to DWR. Thanks. Jay
Hide
Mike Wilson added a comment - 08/May/08 8:59 PM

For questions on how to use DWR please use the mailing list, see http://getahead.org/dwr/support.

Show
Mike Wilson added a comment - 08/May/08 8:59 PM For questions on how to use DWR please use the mailing list, see http://getahead.org/dwr/support.

People

Dates

  • Created:
    06/Mar/08 10:17 AM
    Updated:
    08/May/08 8:59 PM
    Resolved:
    08/Apr/08 12:50 PM