iOS中的Ionic&Cordova奇怪的内存泄漏
  我的离子和科尔多瓦应用程序中有一个奇怪的内存泄漏。  漏洞不在Chrome中,但当我运行该应用程序时,肯定存在。  实质上,我需要遍历一大组数据并将其设置在$scope 。 
  现实生活中的数据是从服务器收集的,但在这里我只是用一个函数来模拟它。  另外,在真正的应用程序中, $scope.vote是通过按钮按$scope.vote调用的,而不是按下按钮来实现for循环。 
这就是说这是一个很好的模拟。 数据较小,但我让循环运行更多,以便您可以真正看到泄漏。 使用我从服务器收集的大型数据集时,泄漏更为重要。
我目前正在运行v1.0.0-beta.13(测试版14对我造成了很多其他问题......)该软件包包含角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分析应用程序显示这一点。 在这个测试案例中,我知道泄漏的大小非常小,但在我的真实应用中,数据量更大,所以这成为一个大问题。 每个颠簸是按钮上连续5次点击的结果。

仪器跟踪文件可在以下网址下载:http://s000.tinyupload.com/?file_id=52410311803253693651
我不会选择这个作为“答案”,因为它不能解决问题,但我会分享我所做的工作,以减少应用程序的内存问题,以防其他人有所帮助。 基本上我做到了这一点:
这大大减少了内存泄漏,但并未完全消除内存泄漏。
我也遇到类似的问题,我花了几个小时优化我的代码来修复它:
上一篇: Odd Memory Leak in Ionic & Cordova for iOS
下一篇: Writing an io.js
