Skip to content
This repository was archived by the owner on Sep 20, 2019. It is now read-only.

Commit 51ead68

Browse files
committed
Fix memory leak in leafletControlHelpers
Fixes issue #279.
1 parent b216a8b commit 51ead68

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

src/directives/controls.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ angular.module('ui-leaflet').directive('controls', function (leafletLogger, leaf
1919
var leafletControls = {};
2020
var errorHeader = leafletHelpers.errorHeader + ' [Controls] ';
2121

22+
scope.$on('$destroy', function () {
23+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
24+
});
25+
2226
controller.getMap().then(function(map) {
2327

2428
leafletScope.$watchCollection('controls', function(newControls) {

src/directives/layers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ angular.module('ui-leaflet').directive('layers', function (leafletLogger, $q, le
2323
updateLayersControl = leafletControlHelpers.updateLayersControl,
2424
isLayersControlVisible = false;
2525

26+
scope.$on('$destroy', function () {
27+
leafletControlHelpers.destroyMapLayersControl(scope.mapId);
28+
});
29+
2630
controller.getMap().then(function(map) {
2731

2832
// We have baselayers to add to the map

src/services/leafletControlHelpers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ angular.module('ui-leaflet').factory('leafletControlHelpers', function ($rootSco
194194
map.addControl(_layersControl);
195195
}
196196
return mustBeLoaded;
197+
},
198+
199+
destroyMapLayersControl: function(mapId) {
200+
delete _controls[mapId];
197201
}
198202
};
199203
});

0 commit comments

Comments
 (0)