dylanfprice / angular-gm

AngularJS Google Maps Directives
MIT License
198 stars 47 forks source link

Event.addListenerOnce not removed on destroy and causing memory leak #45

Closed KevinSchiffmann closed 10 years ago

KevinSchiffmann commented 10 years ago

First of all, thanks a lot for your work on angular-gm :)

When adding listener to a map, event is pushed in an array (_listeners) and then removed on destroy.

this.addMapListener = function(event, handler) {
 var listener = google.maps.event.addListener(this._map, event, handler);

 if (this._listeners[event] === undefined) {
  this._listeners[event] = [];
 }

 this._listeners[event].push(listener);
};

But for listener added once, they aren't. In my case, 'idle' event is never fired, and as it's not removed on destroy, it's causing a memory leak.

controller.addMapListenerOnce('idle', function() {
 scope.$emit('gmMapIdle', scope.gmMapId());
});
this.addMapListenerOnce = function(event, handler) {
 google.maps.event.addListenerOnce(this._map, event, handler);
}

Let me know if you need more details. Thanks!

Edit: It's easily fixable by just adding that event in the listeners array, but i don't know if there's a better solution to handle this.