title: Odd Memory Leak in Ionic & Cordova for iOS
body: <p>I have an odd memory leak in my ionic and cordova app. The leak is not there in chrome but when I ran the app, it is definitely there. Essentially, I need to loop through a large set of data and set it on <code>$scope</code>. </p>
  
  <p>The data in real life is gathered from a server, but here I just simulated it with a function. Also, in the real app, <code>$scope.vote</code> is called by a button press, not a button press that enacts a for-loop. </p>
  
  <p>That said this is a good simulation for it. The data is smaller but I made the loop run more so you can actually see the leak. The leak is much more significant when using the large datasets I'm gathering from the server.</p>
  
  <p>I am currently running v1.0.0-beta.13 (beta 14 is causing a lot of other issues for me...) The bundle contains angular 1.2.25.</p>
  
  <p>I've boiled this down to a test case below:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
      &lt;meta charset="utf-8"&gt;
      &lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"&gt;
      &lt;title&gt;&lt;/title&gt;
  
  
      &lt;!-- compiled css output --&gt;
      &lt;link href="css/ionic.app.css" rel="stylesheet"&gt;
  
      &lt;!-- ionic/angularjs js --&gt;
      &lt;script src="lib/ionic/js/ionic.bundle.js"&gt;&lt;/script&gt;
  
      &lt;!-- cordova script (this will be a 404 during development) --&gt;
      &lt;script src="cordova.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;
          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&lt;=0){
                      getBallots()
                  }
  
              };
  
              $scope.start = function(){
                  for(var i = 0; i &lt; 10000; i++){
                      $scope.vote()
                  }
              }
  
          })
      &lt;/script&gt;
  
  &lt;/head&gt;
  &lt;body ng-app="starter" ng-controller="testCtrl"&gt;
  
  
  {{ballot._id}}&lt;br&gt;
  {{count}}
  &lt;br&gt;&lt;br&gt;&lt;br&gt;
  &lt;button class="button button-large button-royal" ng-click="start()"&gt;BUTTON&lt;/button&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The Instruments tool shows when analyzing the app on my iphone 5S shows this. I know the size of leak is pretty small here in this test case, but in my real app, the data is a lot larger and so this becomes a big problem. Each of the bumps is the result of 5 sequential clicks on the button.</p>
  
  <p><img src="https://i.stack.imgur.com/YYumU.png" alt="enter image description here"></p>
  
  <p>Instruments trace file can be downloaded at: <a href="http://s000.tinyupload.com/?file_id=52410311803253693651" rel="noreferrer">http://s000.tinyupload.com/?file_id=52410311803253693651</a></p>