Przeglądaj źródła

Fixed memory leak in bootstrap Typeahead code, Fixes #1497

Torkel Ödegaard 11 lat temu
rodzic
commit
97e5a04621

+ 0 - 8
src/app/directives/grafanaPanel.js

@@ -37,14 +37,6 @@ function (angular, $, config) {
           var getter = $parse(attr.type), panelType = getter($scope);
           var newScope = $scope.$new();
 
-          $scope.kbnJqUiDraggableOptions = {
-            revert: 'invalid',
-            helper: function() {
-              return $('<div style="width:200px;height:100px;background: rgba(100,100,100,0.50);"/>');
-            },
-            placeholder: 'keep'
-          };
-
           // compile the module and uncloack. We're done
           function loadModule($module) {
             $module.appendTo(elem);

+ 5 - 0
src/app/directives/templateParamSelector.js

@@ -75,6 +75,11 @@ function (angular, app, _, $) {
             $button.focus();
           });
 
+          $scope.$on('$destroy', function() {
+            $button.unbind();
+            typeahead.destroy();
+          });
+
           $compile(elem.contents())($scope);
         }
       };

+ 10 - 7
src/app/features/dashboard/dashboardCtrl.js

@@ -31,13 +31,6 @@ function (angular, $, config, _) {
       $scope.setupDashboard(dashboardData);
     };
 
-    $scope.registerWindowResizeEvent = function() {
-      angular.element(window).bind('resize', function() {
-        $timeout.cancel(resizeEventTimeout);
-        resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
-      });
-    };
-
     $scope.setupDashboard = function(dashboardData) {
       $rootScope.performance.dashboardLoadStart = new Date().getTime();
       $rootScope.performance.panelsInitialized = 0;
@@ -127,5 +120,15 @@ function (angular, $, config, _) {
       $rootScope.$broadcast('render');
     };
 
+    $scope.registerWindowResizeEvent = function() {
+      angular.element(window).bind('resize', function() {
+        $timeout.cancel(resizeEventTimeout);
+        resizeEventTimeout = $timeout(function() { $scope.$broadcast('render'); }, 200);
+      });
+      $scope.$on('$destroy', function() {
+        angular.element(window).unbind('resize');
+      });
+    };
+
   });
 });

+ 6 - 1
src/vendor/bootstrap/bootstrap.js

@@ -1956,7 +1956,7 @@
       return items ? this.process(items) : this
     }
 
-  , process: function (items) {
+    , process: function (items) {
       var that = this
 
       items = $.grep(items, function (item) {
@@ -2050,6 +2050,11 @@
         .on('click', $.proxy(this.click, this))
         .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
         .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
+    },
+
+    destroy: function () {
+      this.$element.off().removeData('typeahead');
+      this.$menu.off();
     }
 
   , eventSupported: function(eventName) {