Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you control memory usage in Cordova?

I'm on iOS now, but the question applies to Android too. I'm looking at the memory graph in Xcode, and my app crashes whenever it hits around 240MB, I believe iOS is killing it because it's taking too much memory.

I can consistently get it to crash by navigating between pages in the app. (It's a SPA, client-side HTML rendering.) If I stop navigating for a minute, the memory will go down to 140MB.

Here is same page in OSX Chrome:

enter image description here

In this case, after ceasing navigation, the memory does not decrease on it's own. Instead, the cliff at the end of the graph is me hitting the garbage collection button (takes it down from 170MB to 60MB).

How do I stop my app from crashing?

  1. Is there an equivalent to the garbage collection button that I can call inside Cordova?
  2. Can I get iOS to give my app a special large memory allowance?
  3. If the user navigates between pages X times within a minute period, I can put up a time-out screen that tells them they can't use the app for the next minute while garbage collection goes XD
  4. Any way to lower the memory usage on the slope up, as JS is rendering HTML?

Also, here is the Chrome graph with HTML nodes – grow proportionally but the nodes stay at same level post garbage collection.

enter image description here

like image 446
Loren Avatar asked Jun 12 '15 23:06

Loren


1 Answers

You could try using the WKWebView plugin, which can sometimes reduce iOS memory usage for Cordova apps.

like image 102
Reubend Avatar answered Nov 25 '22 02:11

Reubend