Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-34210

Memory leak in Jenkins frontend when updating executors

XMLWordPrintable

      In ./war/src/main/webapp/scripts/hudson-behavior.js there is a memory leak triggered by replacing the HTML for the executors panel with fresh content. On installations with a huge list of executors, Chrome can increase in memory usage with over 200MBs every 10minutes by just having the Jenkins dashboard open.

      // refresh a part of the HTML specified by the given ID,
      // by using the contents fetched from the given URL.
      function refreshPart(id,url) {
          var f = function() {
              if(isPageVisible()) {
                  new Ajax.Request(url, {
                      onSuccess: function(rsp) {
                          var hist = $(id);
                          if (hist == null) {
                              console.log("There's no element that has ID of " + id);
                              return;
                          }
                          var p = hist.up();
      
                          var div = document.createElement('div');
                          div.innerHTML = rsp.responseText;
      
                          var node = $(div).firstDescendant();
                          p.replaceChild(node, hist);
       ########## hist cannot be garbage collected after the replaceChild!
       ########## If I comment out applySubtree(node) the memory leak disappears
       ########## So perhaps some event listeners stopping the GC from cleaning up?
                          Behaviour.applySubtree(node);
                          layoutUpdateCallback.call();
      
                          if(isRunAsTest) return;
                          refreshPart(id,url);
                      }
                  });    
              } else {
                  // Reschedule
                  if(isRunAsTest) return;
                  refreshPart(id,url);
              }
              
          };
          // if run as test, just do it once and do it now to make sure it's working,
          // but don't repeat.
          if(isRunAsTest) f();
          else    window.setTimeout(f, 5000);
      }
      
      

            Unassigned Unassigned
            gustafl Gustaf Lundh
            Votes:
            8 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated: