Odd memory leak in Ionic & Cordova for iOS

I have an odd memory leak in my ion and cord application. There is no leak in chrome, but when I launch the application, it definitely is. Essentially, I need to scroll through a large dataset and set it to $scope .

Data in real life is collected from the server, but here I just simulated it using a function. In addition, in a real application, $scope.vote is called by clicking a button, not a button that enters a for loop.

However, this is a good simulation for him. The data is smaller, but I made the loop more active so you can see the leak. Leakage is much more important when using large datasets that I collect from the server.

I am currently running v1.0.0-beta.13 (beta 14 causes many other problems for me ...) The kit contains angular 1.2.25.

I dropped this until the test case below:

 <!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> 

The Tools tool shows when it analyzes the application on my iphone 5S. I know that the leak size here is quite small in this case, but in my real application the data is much larger and this becomes a big problem. Each of the strokes is the result of 5 consecutive clicks on the button.

enter image description here

The tool trace file can be downloaded at: http://s000.tinyupload.com/?file_id=52410311803253693651

+7
angularjs ios memory-leaks cordova ionic-framework
source share
2 answers

I will not choose this as the “answer” because it does not solve the problem, but I will share what I did to reduce the memory problem of the application, if it is useful to someone else. Essentially I did this:

  • upgrade to ion beta14, angular 1.3.6
  • rewrite logic to remove any "ng-ifs" that have been re-created / destroyed. I replaced them with ng shows or something related to CSS.

This reduced a memory leak, but did not completely remove the memory leak.

+4
source share

I also had similar issues and spent hours optimizing my code to fix this:

  • switches to the track using ng options, that is, "activity.name for activity in actions track by activity.id" (<- this had the greatest impact).
  • removed as many ng-show / ng-if as possible
  • all $ rootScope variables have been removed (should not be (m) first)
  • deleted all the 'watch' tasks and replaced them with events - I destroyed ($ destroy) the ones you need only once
  • the number of $ scope variables is reduced ... in fact, I / should / should use controllerAs-Syntaxt ( http://toddmotto.com/digging-into-angulars-controller-as-syntax/ ) in the next step
0
source share

All Articles