iOS7 webkit 频繁崩溃——没有释放内存? [英] iOS7 webkit crashes frequently - not freeing up memory?
问题描述
我注意到我的 Phonegap 应用在 iOS7 上出现了一些在 iOS6 上没有发生的内存问题.
I'm noticing my Phonegap app is having some memory issues on iOS7 that weren't happening on iOS6 .
- 带有许多图像的长 iScroll 列表
- 显示手机相册中的图像 (9mp) 会在您查看多个图像后崩溃
对于#1,无论设备如何,这在 iOS6 上都不是问题.
For #1, this was never an issue on iOS6, regardless of device.
对于#2,我重新使用相同的 DIV 元素来显示下一张图片,所以看起来上一张图片没有被清除.
For #2, I am re-using the same DIV element to display the next picture, so it seems that the previous image is not being cleared.
本文中提到的技术似乎不再适用于 iOS7:在 Javascript 中加载图像时 iPad/iPhone 浏览器崩溃
The techniques mentioned in this post no longer appear to work in iOS7: iPad/iPhone browser crashing when loading images in Javascript
推荐答案
我找到的这个问题的最佳解决方案是以下代码:
The best solution for this problem I found is the following code:
var img = document.getElementById('imageID');
img.parentNode.removeChild(img);
img.src = 'data:image/gif;base64,' +
'R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
setTimeout(function() {
img = null;
}, 60000);
这会将 src 属性设置为一个很小的 gif,然后等待足够长的时间以最终发生垃圾收集.
This sets the src attribute to a tiny gif and then waits long enough for garbage collection to happen eventually.
参见:http://www.fngtps.com/2010/mobile-safari-image-resource-limit-workaround/
这应该对你有用.我可以使用 Xcode 工具验证内存是否已释放.不幸的是,此解决方案似乎不适用于我正在使用的主屏幕应用程序.
This should work for you. I could verify that the memory is released by using the Xcode instruments. Unfortunately this solution doesn't seem to work for homescreen apps which I am using.
这篇关于iOS7 webkit 频繁崩溃——没有释放内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!