4

When I run this code, the number of calls seems to be limited to about 1000

var i = 1;
$interval(function() {
  navigator.geolocation.getCurrentPosition(function(position) {
    console.log('Plugin call number', i);
  });
  i++;
}, 10);

Is there a way to overstep this limit?

Edit 1: This is just an example. In my case, I have custom camera plugin, and one of the method is called at every "pinch in" or "pinch out" event.

Edit 2: When the limit is reached, the app just stops calling the plugin (in this case, it stops at 1004) enter image description here

Also, the memory usage won't stop growing enter image description here

Edit 3: It seems that the issue only occurs in Ionic. I've tried this code in a pure Cordova app, and the number of calls doesn't seem to be limited (also the memory usage grows way more slowly)

onDeviceReady: function() {
    app.receivedEvent('deviceready');
    if (window.cordova) {
        var i = 1;
        setInterval(function() {
            navigator.geolocation.getCurrentPosition(function(position) {
                console.log('Plugin call number', i);
            });
            i++;
        }, 10);
    }
}
JMaylin
  • 1,378
  • 4
  • 15
  • 38
  • Can you tell us what happens when the "limit" is reached? – Sithys Apr 14 '15 at 06:39
  • @Sithys Thanks for your interest. I've added a couple of screenshots – JMaylin Apr 14 '15 at 07:45
  • I think it stops working because of the memory usage but i'm just testing sth with the plugin and your script. Give me some time and i'll report my results. – Sithys Apr 14 '15 at 07:51
  • @Sithys I forgot to mention that I use Cordova through Ionic. I just made some tests on a pure Cordova app, and the issue doesn't seem to occur – JMaylin Apr 14 '15 at 08:05
  • Could you provide a full code snippet of the code in your pure cordova app? – Sithys Apr 14 '15 at 08:10
  • i can confirm what you just tested. In a blank cordova only app the problem doesn't exist. My calls reached 10000 and nothing happens. Memory stops crawling up at 28Mb – Sithys Apr 14 '15 at 08:20
  • Well, I guess Ionic has some problems to manage the memory, because with my pure Cordova app, the memory usage is 110 MB after 120000 calls (and it still runs) – JMaylin Apr 14 '15 at 08:27
  • The app will crash at about 450Mb Memory Usage – Sithys Apr 14 '15 at 08:31
  • I am using Ionic for my application and this information will be useful since I am adding many plugins for my functions. Thank you for pointing this out. Seems like Ionic is yet to be optimized in terms of memory usage. – Keval Apr 14 '15 at 10:50
  • This is not the way you should use a plugin apparently. So why not use [keepCallback](http://stackoverflow.com/questions/18758756/keep-callback-context-in-phonegap-plugin) within each kind of plugin for ios, android, wp8? Therefore you do not have to call a plugin explicitly within you webview-app but you get notified by it automatically depending on how it's been programmed. – Blauharley Apr 18 '15 at 08:53

1 Answers1

0

Ionic is built on Angular, which is notorious for suffering from performance problems after hitting about 2,000 data bindings. Without seeing your source it's hard to tell exactly what's going on, but if the pinching action is creating new bindings that may be the case. Check to see if your pinch calls are initiating new data bindings and if so, you may need to optimize your app to use one way bindings, bind-once bindings or release them from scope.

Community
  • 1
  • 1
lastcommit
  • 106
  • 4