无论我使用以下单张指令,我的Angular应用程序中都有明显的内存泄漏:https://github.com/tombatossals/angular-leaflet-directive。AngularJS单张内存泄漏
请注意,该指令工作正常,但内存占用继续增长,因为我离开并返回到使用该指令的任何视图。
该指令建立关闭JavaScript库,发现这里的传单:https://github.com/Leaflet/Leaflet
我用的指令,如下所示:
<div ng-controller="Explore">
<div leaflet defaults="defaults" center="center" markers="markers" layers="layers"></div>
</div>
在我的控制我延长传单指令属性范围:
angular.extend($scope, {
defaults: {
dragging: true,
doubleClickZoom: false,
scrollWheelZoom: false,
maxZoom: 12,
minZoom: 12
},
center: {
lat: $scope.cities[$scope.market.city][1],
lng: $scope.cities[$scope.market.city][0],
zoom: 12
},
markers: {},
layers: {
baselayers: {
google: {
name: 'Google Streets',
layerType: 'ROADMAP',
type: 'google'
}
}
}
});
我不确定是什么导致内存泄漏,但我相信它可能与事件侦听器不会被删除时$破坏为瓣叶指令中称为:
scope.$on('$destroy', function() {
leafletData.unresolveMap(attrs.id);
});
在破坏功能unresolveMap叫:
this.unresolveMap = function (scopeId) {
var id = leafletHelpers.obtainEffectiveMapId(maps, scopeId);
maps[id] = undefined;
};
这是据我得到了。如果有人遇到过类似的问题或者对如何进一步攻击这个问题有任何想法,我将不胜感激:)
我刚才也注意到了这一点,并想知道你是否有任何进展确定泄漏发生在哪里? – BrokenRobot
你有没有解决这个问题? – Lugaru