如果不在“可见范围内"以节省内存,如何卸载图像? [英] How to unload image when not 'in view' to save memory?

查看:80
本文介绍了如果不在“可见范围内"以节省内存,如何卸载图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的图片库,我希望这些图片可以在移动设备上显示,而不会导致浏览器崩溃或卷动.周围有大量的插件可以延迟加载图像,但是当没有视图时,有没有什么可以卸载图像以节省内存?

I've got a looong gallery of pictures that I'd like to be able to display on mobile devices without browsers crashing or causing jerky scrolling. Loads of plugins around to lazy load images but is there anything out there to unload the images when not in view to save memory?

推荐答案

这是LinkedIn工程团队博客文章

This is a quote from the LinkedIn Engineering team blog post LinkedIn for iPad: 5 techniques for smooth infinite scrolling in HTML5 that is relevant to this question:

UIWebView/移动Safari具有,而不会遇到内存问题.但是,我们发现在画布上绘制非常大的图像的速度很慢,因此我们不得不采取另一种方法:每当将图像从屏幕上充分刷除时,我们都会用非常小的图像替换img标签的"src"属性.这样可以确保定期释放用于渲染大图像的内存.另外,我们确保不引入空图片src属性错误.

UIWebView/Mobile Safari have strict limits for images. Our stream is full of big images, so we hit the limits very quickly. One option was to use the HTML5 Canvas element to draw images without running into memory issues. However, we found drawing very big images on canvas was slow, so we had to take another approach: whenever an image was swiped sufficiently off screen, we replaced the "src" attribute of the img tag with a very small image. This ensured that the memory used for rendering large images was freed up periodically. Also, we ensured that we did not introduce the empty image src attribute bug.

这篇关于如果不在“可见范围内"以节省内存,如何卸载图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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