最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can you control memory usage in Cordova? - Stack Overflow

programmeradmin0浏览0评论

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:

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.

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:

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.

Share Improve this question asked Jun 12, 2015 at 23:10 LorenLoren 14.9k9 gold badges52 silver badges81 bronze badges 5
  • 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 Commented Jun 13, 2015 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 Commented Jun 14, 2015 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 e back with the answer. – YvesLeBorg Commented Jun 14, 2015 at 21:29
  • @Loren did the plugin work for Android too? – VaTo Commented Sep 25, 2015 at 20:34
  • There is no WKWebView plugin for Android, but Crosswalk should help. – Loren Commented Sep 25, 2015 at 23:47
Add a ment  | 

1 Answer 1

Reset to default 4

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

发布评论

评论列表(0)

  1. 暂无评论