17

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

Loren
  • 13,903
  • 8
  • 48
  • 79
  • did you profile this on iOS , especially for leaks ? that seems like a lot of memory when you consider what is left for apps after memory hungry iOS takes its pound of flesh in the device. And i know no way of getting iOS to allocate you extra memory, even for 'native' apps. – YvesLeBorg Jun 13 '15 at 21:30
  • Correct me if I'm wrong, but I believe since everything is happening in the UIWebView, profiling in devtools should catch the same things that iOS profiling would catch? And since the heap went down to baseline after garbage collection, that means there aren't leaks? – Loren Jun 14 '15 at 16:02
  • 1
    duh, my bad. I did look in the native iOS code, and found something weird. Posting a question on github, will come back with the answer. – YvesLeBorg Jun 14 '15 at 21:29
  • @Loren did the plugin work for Android too? – VaTo Sep 25 '15 at 20:34
  • There is no WKWebView plugin for Android, but Crosswalk should help. – Loren Sep 25 '15 at 23:47

1 Answers1

4

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

Reubend
  • 644
  • 1
  • 6
  • 19
  • Glad to hear it worked out so well! That's a fantastic improvement. – Reubend Aug 13 '15 at 01:20
  • Actually, I think WKWebView memory must not be included in the XCode memory chart [1], because I still get memory warnings and crashing. I think less often though. [1] https://github.com/practicalmeteor/meteor-wkwebview/issues/1#issuecomment-130521832 – Loren Aug 13 '15 at 04:43
  • @Reubend Is there anything like that for Android? – VaTo Sep 25 '15 at 20:32
  • @SaulOrtega Yes, actually there is something similar for Android. The [Crosswalk web view](https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview) can improve performance on older devices, although I don't think it reduces memory usage. Keep in mind that it has both advantages and disadvantages. – Reubend Sep 26 '15 at 07:42
  • The performance boost is incredible with this plugin - but my video files no longer play with the player plugin I use – kris Feb 28 '17 at 05:52