Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhoneGap using way more memory in iOS8 than iOS7

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

PhoneGap Canvas app running under iOS 7

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.

PhoneGap Canvas app running under iOS 8

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.

like image 282
Nitzan Wilnai Avatar asked Sep 28 '14 20:09

Nitzan Wilnai


1 Answers

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

like image 148
Nitzan Wilnai Avatar answered Nov 17 '22 11:11

Nitzan Wilnai