K-Meleon: Use a different approach to save timers (prevents a memory leak) ADBLOCK_PLUS_1_0_BRANCH
authorWladimir Palant <trev@adblockplus.org>
Wed, 23 Jun 2010 13:37:32 +0200
branchADBLOCK_PLUS_1_0_BRANCH
changeset 2124f31040367dc5
parent 2123 64851199d6df
child 2125 ef444f7712ec
K-Meleon: Use a different approach to save timers (prevents a memory leak)
kmeleon/window.js
     1.1 --- a/kmeleon/window.js
     1.2 +++ b/kmeleon/window.js
     1.3 @@ -13,34 +13,35 @@ function removeEventListener(event, hand
     1.4    if (event == "load")
     1.5      _loadListeners = _loadListeners.filter(function(item) {return item != handler});
     1.6  }
     1.7  function _notifyLoadListeners() {
     1.8    for (var i = 0; i < _loadListeners.length; i++)
     1.9      _loadListeners[i].call(window);
    1.10  }
    1.11  
    1.12 -var _timers = [];
    1.13 +var _timers = {last: 0};
    1.14  function setInterval(callback, delay) {
    1.15    var timer = Components.classes["@mozilla.org/timer;1"]
    1.16                          .createInstance(Components.interfaces.nsITimer);
    1.17    timer.init({observe: callback}, delay, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
    1.18 -  _timers.push(timer);
    1.19 +  _timers[++_timers.last] = timer;
    1.20  }
    1.21  function setTimeout(callback, delay) {
    1.22 +  var index = ++_timers.last;
    1.23    var timer = Components.classes["@mozilla.org/timer;1"]
    1.24                          .createInstance(Components.interfaces.nsITimer);
    1.25    timer.init({
    1.26 -    observe: function(){
    1.27 -      delete _timers[this.index];
    1.28 +    observe: function() {
    1.29        callback();
    1.30 -    },
    1.31 -    index: _timers.length
    1.32 +      delete _timers[index];
    1.33 +      timer = null;
    1.34 +    }
    1.35    }, delay, Components.interfaces.nsITimer.TYPE_ONE_SHOT);
    1.36 -  _timers.push(timer);
    1.37 +  _timers[index] = timer;
    1.38  }
    1.39  
    1.40  function delayedOpenTab(url)
    1.41  {
    1.42    var hWnd = (_currentWindow && !_currentWindow.closed ? _windowMediator.toHWND(_currentWindow) : null);
    1.43    openTab(url, hWnd);
    1.44  }
    1.45  
    1.46 @@ -67,9 +68,9 @@ var _classInfo = {
    1.47      count.value = 0;
    1.48      return [];
    1.49    },
    1.50    QueryInterface: window.QueryInterface
    1.51  }
    1.52  
    1.53  this.__defineGetter__("content", function() {
    1.54    return (_currentWindow && !_currentWindow.closed ? _currentWindow : {location: {href: "about:blank"}});
    1.55 -});
    1.56 \ No newline at end of file
    1.57 +});