Ionic&;iOS版科尔多瓦
我的ionic和cordova应用程序有一个奇怪的内存泄漏。chrome中没有漏洞,但当我运行应用程序时,它肯定在那里。基本上,我需要遍历一大组数据并将其设置为Ionic&;iOS版科尔多瓦,ios,angularjs,cordova,memory-leaks,ionic-framework,Ios,Angularjs,Cordova,Memory Leaks,Ionic Framework,我的ionic和cordova应用程序有一个奇怪的内存泄漏。chrome中没有漏洞,但当我运行应用程序时,它肯定在那里。基本上,我需要遍历一大组数据并将其设置为$scope 现实生活中的数据是从服务器收集的,但这里我只是用一个函数来模拟它。此外,在真正的应用程序中,$scope.vote是通过按钮按下来调用的,而不是通过按钮按下来执行for循环 也就是说,这是一个很好的模拟。数据较小,但我使循环运行得更多,因此您可以实际看到泄漏。当使用从服务器收集的大型数据集时,泄漏更为严重 我目前运行的是v1
$scope
现实生活中的数据是从服务器收集的,但这里我只是用一个函数来模拟它。此外,在真正的应用程序中,$scope.vote
是通过按钮按下来调用的,而不是通过按钮按下来执行for循环
也就是说,这是一个很好的模拟。数据较小,但我使循环运行得更多,因此您可以实际看到泄漏。当使用从服务器收集的大型数据集时,泄漏更为严重
我目前运行的是v1.0.0-beta.13(beta 14给我带来了很多其他问题…),包中包含angular 1.2.25
我将其归结为以下一个测试用例:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<script>
angular.module('starter', ['ionic'])
.controller("testCtrl", function($scope){
$scope.b = [];
$scope.count = 0;
function getBallots() {
$scope.b.push({
_id: "54d7d680bdd622982e91a45f"
});
$scope.b.push({
_id: "54d7ef2ac659dd302a128924"
});
$scope.b.push({
_id: "54d7ef2ac659dd302a128929"
});
}
getBallots();
$scope.vote = function(){
if($scope.b.length){
$scope.ballot = $scope.b.shift();
$scope.count ++;
}
if($scope.b.length<=0){
getBallots()
}
};
$scope.start = function(){
for(var i = 0; i < 10000; i++){
$scope.vote()
}
}
})
</script>
</head>
<body ng-app="starter" ng-controller="testCtrl">
{{ballot._id}}<br>
{{count}}
<br><br><br>
<button class="button button-large button-royal" ng-click="start()">BUTTON</button>
</body>
</html>
角度模块('starter',['IONAL']))
.controller(“testCtrl”,函数($scope){
$scope.b=[];
$scope.count=0;
函数getBallots(){
$scope.b.push({
_id:“54d7d680bdd622982e91a45f”
});
$scope.b.push({
_id:“54d7ef2ac659dd302a128924”
});
$scope.b.push({
_id:“54d7ef2ac659dd302a128929”
});
}
获取选票();
$scope.vote=函数(){
如果($scope.b.长度){
$scope.ballot=$scope.b.shift();
$scope.count++;
}
如果($scope.b.length,我不会选择这个作为“答案”,因为它不能解决问题,但我会分享我为减少我的应用程序内存问题所做的工作,以防对其他人有所帮助。基本上我这样做了:
升级至离子型beta14,角度1.3.6
重写逻辑以删除重复创建/销毁的任何“ng IF”。我用ng Show或css相关的东西替换了这些
这大大减少了内存泄漏,但并没有完全消除内存泄漏。我也遇到过类似的问题,我花了几个小时优化代码以修复它:
- 切换到ng选项中的跟踪方式,即“activity.name for activities in activities track by activity.id”(这里不是科尔多瓦专家,但这是一个写得非常好的问题,也是一个非常好的MCVE示例。干杯。你找到了任何解决方案吗?@confile不太确定。请参阅下面我的答案,了解我为最小化问题所做的工作。我非常确定angular/ionic只是在总体上泄漏了一点。)