Skip to content
Permalink
Browse files

[JENKINS-10912] Use setInterval in refreshPart (#2539)

* [JENKINS-10912] Use setInterval in refreshPart

The current implementation of refreshPart creates a new closure every 5
seconds, which, in combination with XMLHttpRequest objects, results in a
significant memory leak in all major browsers. By using
window.setInterval to schedule periodic refreshes, only one closure per
id is created. Please see issue #10912 in the Jenkins tracker for
further details.

* Stop periodical calls if we can't find the div

* Don't check if isRunAsTest changed after page load
  • Loading branch information...
lpancescu authored and daniel-beck committed Sep 18, 2016
1 parent 423fca9 commit 096614a6d72c19633909248cb5b06a179b8b4040
Showing with 5 additions and 10 deletions.
  1. +5 −10 war/src/main/webapp/scripts/hudson-behavior.js
@@ -1486,13 +1486,16 @@ function expandTextArea(button,id) {
// 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 intervalID = null;
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);
if (intervalID !== null)
window.clearInterval(intervalID);
return;
}
var p = hist.up();
@@ -1505,22 +1508,14 @@ function refreshPart(id,url) {

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);
else intervalID = window.setInterval(f, 5000);
}


0 comments on commit 096614a

Please sign in to comment.
You can’t perform that action at this time.