PhoneGap在iOS8中使用比iOS7更多的内存 [英] PhoneGap using way more memory in iOS8 than iOS7

查看:269
本文介绍了PhoneGap在iOS8中使用比iOS7更多的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PhoneGap应用程序。一个HTML5画布游戏。它似乎在iOS 8(包括8.0.2)和iOS 7中使用显着更多的内存。



除了使用更多的内存,JS垃圾收集器似乎永远释放它所持有的内存。它正在收集释放内存,但不会将其释放回iOS以供使用。



这是使用仪器分配在iOS 7下与iPhone 5S的内存使用。正如你可以看到,它加载和下载,因为我加载和卸载一个级别。此外,内存使用率非常低,约为23MB,最高为41.81mb。





这里是运行在iPhone 5S与iOS 8.0.2上的同一个应用程序。正如你可以看到的内存使用从来没有下降,它使用显着更多的内存。实际上,当我加载和卸载相同的级别时,内存使用持续上升。它不会上升到那么高,这让我认为JS正确地重新使用来自Garbage Collector的内存,但GC似乎从来没有释放它回到操作系统的内存。此外,整个应用程序似乎使用方式比以前更多的内存。



该应用程序运行速度慢得多,在我停止它时达到121mb。



我应该补充一点,当卸载级别时,我重新加载页面,这很奇怪,不会释放iOS 8下的任何内存。



有没有人有什么想法可能会导致这个问题和解决方案可能是什么?这是iOS 8中的一个错误?



在8.0(但不是8.1),可以使用一个解决方法/ hack:调用 window.location。在使用 window.location.href = 强制重新加载页面之前,重新加载(true); 。自从8.1这个黑客/解决方法不起作用。

解决方案

最终解决了。



PhoneGap默认使用UIWebView,因为WKWebView中的文件加载错误。以上错误只发生在UIWebView。



我安装了下面的插件,修复了WKWebView中的文件加载错误。这让我使用WKWebView没有上面的内存错误。



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


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.

解决方案

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

这篇关于PhoneGap在iOS8中使用比iOS7更多的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆