简体   繁体   English

在iPad 2上的Safari中动态加载图像会导致内存泄漏

[英]Dynamically loading images in Safari on iPad 2 causes memory leak

I'm developing a game on HTML5 and it has a memory leak problem when running on iPad 2. In the memory trace, I see loaded images occupied almost used memory and it's never released. 我正在使用HTML5开发游戏,并且在iPad 2上运行时遇到内存泄漏问题。在内存跟踪中,我看到加载的图像占用了几乎已用的内存,并且从未发布过。

So, It's reason why I want to know extractly: how does browser keep images on memory? 所以,这就是为什么我想知道的原因:浏览器如何将图像保存在内存中?

In my imagination, the cycle begins when HTML parser of browser reach an Image DOM element, it loads the image data from URL into memory and render it to screen. 在我的想象中,循环从浏览器的HTML解析器到达Image DOM元素开始,它将URL中的图像数据加载到内存中并呈现到屏幕上。

So, when is the image data released from memory? 那么,何时从内存中释放图像数据? Or how to release it manually? 或者如何手动释放它?

Some code could be interesting, to see how you manage your images in your applicayion. 一些代码可能很有趣,以了解如何在应用程序中管理图像。

Anyway a good tips for memory leak problems with images on ipad 3 (not sure for the 2 but i believe yes) it's to use a simple CSS Rule like that : 无论如何,关于ipad 3上图像的内存泄漏问题的好提示(不确定2的图像,但我相信是),它是使用像这样的简单CSS规则:

img{
    -webkit-transform: translateZ(0); 
}

This simple rule will enable the 3D acceleration, but use it only when you really need it. 这个简单的规则将启用3D加速,但仅在确实需要时才使用。

Hope it helps a little 希望能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM