2

I have web app that does periodic scan operations, and on a specific page, shows the status of those operations (and any previously-completed ones). I have an Ajax request that I send using jQuery, and it returns the same page I'm currently on, modified given a time variable (last updated) to include just the running scans and any recently completed ones.

Apparently, after leaving this open overnight, which isn't a normal use case, on IE8 an 'out of memory at line 112' (nothing notable at line 112 in anything) was returned. I'm trying to figure out what I'm doing wrong, and where it could be leaking.

My question is: since I'm reloading the same page, but only taking a piece of it, are the 'ready' handlers getting rerun or something? For the most part, the active operations table is going to be empty, so it's not like I'm continually increasing the size of the table or something obvious.

function updateActiveScanList()
 {
    $.ajax({  
        method: "POST",
        url: "ScanList.action",
        data: { updatedTime: $('#updatedTime').val() },
        success: function(data) { 


        // Update the active scan list.
        $('#activescans').html( $("#activescans", data) );

        // the recent scans table update requires more massaging, omitted for brevity,
        // since there's nothing else done there, this happens even if nothing else is 
        // ever inserted.
    });
}
$(document).ready(

  function(){
      setInterval( updateActiveScanList, 30000 );
  } 
);
Shawn D.
  • 7,895
  • 8
  • 35
  • 47
  • 3
    Just an FYI, it is considered bad practice to pass strings to `setTimeout()` and `setInterval()` (because you're basically `eval()-ing`). You should pass functions instead: `setInterval(updateActiveScanList, 30000);` – Matt Ball Nov 18 '10 at 15:14
  • The real problem may be caused when the **HTML** is replaced inside the `#activescans`, also if you are attaching data to the generated HTML, then each time you run the **AJAX** request, the **DOM** elements previously in `#activescans` are destroyed, but the associated data could remain untouched. See this stackoverflow: **[jQuery memory leak with DOM removal](https://stackoverflow.com/questions/1462649/jquery-memory-leak-with-dom-removal)** – jherax Jun 16 '15 at 17:58

1 Answers1

4

You can use a tool like sIEve to detect the things that eat your memory.
I guess the number of used DOM-nodes(they don't need to be a part of the document-tree) will increase with every manipulation.

It would be the best if you forget jQuery for the part of the DOM-manipulation, the methods jQuery uses are known as prone to this issue, while they partial use some "dirty" things like innerHTML.

Can you give an example of what you like to have inside #activescans?

Dr.Molle
  • 116,463
  • 16
  • 195
  • 201
  • Well, that definitely shows me that the # of orphaned DOM nodes in use is going up by 24 each request, there's nothing obvious in my code that indicates how I would get rid of them, or why they're not being cleaned up. Any suggestions? – Shawn D. Nov 18 '10 at 17:30
  • Suggestions: maybe(see my edited post). It depends on what you like to show there, and if it could be build out of the response on a clean way, using native DOM-methods only. – Dr.Molle Nov 18 '10 at 17:39
  • For the most part, the DOM that's returned contains almost nothing in the 99% case. If there's nothing running, it just contains an

    Active Scans

    There are no active scans.

    , but there is a
    – Shawn D. Nov 25 '10 at 14:10