PhoneGap using way more memory in iOS8 than iOS7

爷,独闯天下 提交于 2019-12-08 23:08:05

问题


I have a PhoneGap app. An HTML5 Canvas game. It appears to use significantly more memory in iOS 8 (including 8.0.2) vs iOS 7.

In addition to using more memory, the JS Garbage Collector does not seem to ever free up the memory it is holding. It is collecting "freed" memory correctly, but never releasing it back for iOS to use.

Here is the memory usage using Instruments Allocations under iOS 7 with an iPhone 5S. As you can see it goes up and down as I load and unload a level. Also the memory usage is very low, at around 23mb, maxing at 41.81mb

Here is the same app running on an iPhone 5S with iOS 8.0.2. As you can see the memory usage never goes down and it uses significantly more memory. In fact the memory usage keeps going up forever as I load and unload the same level. It doesn't go up as high, which makes me think JS is correctly re-using memory from the Garbage Collector, but the GC never seems to free the memory it is holding back to the OS. Also the entire app seems to be using way more memory than before.

The app also runs a lot slower and reached 121mb by the time I stopped it.

I should add that when unloading the level I re-load the page, which curiously does not free up any memory under iOS 8.

Does anyone have any ideas what could be causing this problem and what the solution might be? Is this a bug in iOS 8?

In 8.0 (but not 8.1) one could free using a workaround/hack: calling window.location.reload(true); before forcing a page reload using window.location.href =. Since 8.1 this hack/workaround doesn't work.


回答1:


Finally solved.

PhoneGap defaults to use UIWebView because of a file loading bug in WKWebView. The above bug happens only in UIWebView.

I installed the following plugin that fixes the file loading bug in WKWebView. This let me use WKWebView which does not have the memory bug above.

https://github.com/Telerik-Verified-Plugins/WKWebView



来源:https://stackoverflow.com/questions/26089354/phonegap-using-way-more-memory-in-ios8-than-ios7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!