angular-ui / ui-map

Google Maps
http://angular-ui.github.io/ui-map
MIT License
288 stars 93 forks source link

Memory leak in directives for some use cases #37

Open stianlik opened 10 years ago

stianlik commented 10 years ago

The bindMapEvents()-function attaches events to google-maps objects, but it does not handle unbinding when objects are removed (or replaced).

The following use case will cause a memory leak each time setProject() is called.

var markers = {
    "firtProject": [/* list of  Google Maps markers */],
    "secondProject": [/* list of Google Maps markers */]
};
$scope.setProject = function(project) {
    $scope.markers = markers[project];
};
$scope.markerClicked = function(marker) {
    /* some action */
};
<button ng-click="setProject('firstProject')">Project 1</button>
<button ng-click="setProject('secondProject')">Project 2</button>
<div ng-repeat="marker in markers" ui-map-marker="markers[$index]" ui-event="{'map-click': 'markerClicked(marker)'}"></div>

Directive should store unbind markers when they are removed from scope.