ipad 内存问题在 UIWebView 中加载图像
我有一个与此类似的问题: 在 Javascript 中加载图像时 iPad/iPhone 浏览器崩溃
...但我想澄清一下,我的问题是由相同的内存问题引起的,如果是这样,我可以采取什么措施。
我理解为不在视图中的 img 元素加载“tiny.gif”图像的建议解决方法,但问题是,我没有使用大量的 img 元素。我用的是四个三个位于滑动 div 中,在下一张/上一张图像中滑动,还有一个在滑动 div 进行滑动操作时显示当前图像。解释这个机制有点困难,但重点是,只有四个图像元素,我只是不断地交换它们的 src。
所以我不明白的是..如果内存中只有四个 img 元素,我如何遇到内存问题?如果slide_one是一个src为one.jpg的图像,我将其src更改为two.jpg,那么one.jpg肯定会被清理出内存,对吗?
简单介绍一下背景:我正在通过 UIWebView 作为 iPad 应用程序运行 HTML 页面。我看到的行为是,我可以加载大约 25 个每个图像大约 250kb 的 JPEG,然后它停止加载它们(src 属性已更新,但图像明显保持不变)。这听起来与我听说过的 6MB 限制非常相似,但我没有看到任何警告或崩溃(至少在我调试这个的 iPhone 模拟器中没有)。
非常感谢您收到的任何建议...:)
I've got an issue similar to this one:
iPad/iPhone browser crashing when loading images in Javascript
... but I'd like to clarify that my issue is caused by the same memory issue, and if so, what I can do about it.
I understand the proposed workaround of loading "tiny.gif" images for img elements that aren't in view, but the thing is, I'm not using loads of img elements. I'm using four. Three in a sliding div that slides in the next/prev image, and one that displays the current image while the sliding div is doing its sliding thing. It's a little hard to explain the mechanism, but the point is, there's only four image elements and I'm just continually swapping their src.
So what I don't get is.. if there's only four img elements in memory, how am I running up against the memory issue? If slide_one is an image with a src of one.jpg, and I change its src to two.jpg, surely one.jpg is cleaned out of memory, right?
Just a little background: I'm running a HTML page through a UIWebView as an iPad app. The behaviour I'm seeing is that I can load about 25 of these roughly-250kb-per-image JPEGs, and then it stops loading them (the src attribute is updated but the image stays blatantly unchanged). This sounds suspiciously similar to the 6MB limit I've heard mentioned, but I'm not seeing any warning or crash (at least, not in the iPhone Simulator where I'm debugging this).
Any advice gratefully received... :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
FWIW,我通过在包含的 div 上交换 bg 图像来解决这个问题,而不是使用 img 元素并交换其 src。
因此,要么是内存管理不允许加载超过 x MB 的图像的错误,要么是背景图像不计入总数的错误。
哼。
FWIW, I solved this by swapping bg image on the containing div rather than using an img element and swapping its src.
So either it's a bug that memory management doesn't allow more than x MB of images loaded, or it's a bug that bg images don't count towards that total.
Ho-hum.