angular-ui / ui-leaflet

AngularJS directive to embed an interact with maps managed by Leaflet library
http://angular-ui.github.io/ui-leaflet
Other
314 stars 134 forks source link

Memory leak caused by leafletControlHelpers.updateLayersControl #279

Closed apkoponen closed 8 years ago

apkoponen commented 8 years ago

Hi,

I'm using the directive to show markers on maps that all have a different ID. There seems to however be a memory leak in leafletControlHelpers, which is caused by _controls[mapId] holding a reference to map data, which is not destroyed when the directive gets destroyed.

I was able to get rid of the memory leak by changing the line https://github.com/angular-ui/ui-leaflet/blob/master/src/services/leafletControlHelpers.js#L162 to

            var _layersControl = _controls[mapId];
            _controls = {};
            _controls[mapId] = _layersControl;

which removes all but the current references from the _controls object.

This is not a suitable workaround though, because it essentially prevents having multiple directives running at the same time. Do you have any suggestions as to how to remove the reference when the map with the corresponding mapId is destroyed?

A-P

elesdoar commented 8 years ago

Fixed with #281