gpt4 book ai didi

ios - 适用于 iOS 的 Ionic 和 Cordova 中的奇怪内存泄漏

转载 作者:可可西里 更新时间:2023-11-01 03:32:17 24 4
gpt4 key购买 nike

我的 ionic 和 cordova 应用程序出现奇怪的内存泄漏。 chrome 中没有泄漏,但当我运行该应用程序时,它肯定存在。本质上,我需要遍历大量数据并将其设置在 $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>

在我的 iPhone 5S 上分析应用程序时,Instruments 工具显示了这一点。我知道在此测试用例中泄漏的大小非常小,但在我的真实应用程序中,数据要大得多,所以这成为一个大问题。每个颠簸都是连续点击按钮 5 次的结果。

enter image description here

仪器跟踪文件可在以下网址下载:http://s000.tinyupload.com/?file_id=52410311803253693651

最佳答案

我不会选择这个作为“答案”,因为它不能解决问题,但我会分享我为减少应用内存问题所做的工作,以防对其他人有帮助。基本上我是这样做的:

  1. 升级到 ionic beta14,angular 1.3.6
  2. 重写逻辑以删除任何重复创建/销毁的“ng-ifs”。我用 ng-shows 或与 css 相关的东西替换了它们。

这显着减少了内存泄漏,但并未完全消除内存泄漏。

关于ios - 适用于 iOS 的 Ionic 和 Cordova 中的奇怪内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28424762/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com