移动WebKit的内存消耗消耗、内存、WebKit

2023-09-05 00:38:59 作者:半夢半醒半浮生

我们正在开发HTML5应用程序的移动设备(安卓+ IOS)。但最大的问题是内存消耗 - 使用的内存量上升非常快,应用程序成为laggy

We are working on HTML5 application for mobile devices(Android + iOS). But the great problem is memory consumption - used memory amount is rising very fast and app become laggy.

什么是最好的做法,提示,工具,解决方案等,为有内存泄漏战斗在HTML(JavaScript)的应用程序?

What are the best practices, hints, tools, solutions, etc. for fighting with memory leaks in HTML(JavaScript) applications ?

PS 我们Webkit的浏览器只针对

P.S. We are targeting only on Webkit browsers

推荐答案

已经有关于这个问题的一些真正伟大的文章最近。有一些着实令人吃惊对象创建的来源并没有真正引起你的注意,除非你调整它。通常情况下,这个问题是不是内存的使用,它实际上是收集内存中的应用程序是慢慢渗出所需的垃圾收集周期。

There have been some really great articles on this subject recently. There are some really surprising sources of object creation that don't really catch your attention unless you're tuned for it. Typically, the problem isn't the memory use, it's actually the garbage collection cycles required to collect the memory the app is slowly leaking.

这文章是最好的,我读过的话题近期:http://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascript

This article is the best I've read on the topic recently: http://www.scirra.com/blog/76/how-to-write-low-garbage-real-time-javascript

至于工具打击/诊断问题,谷歌Chrome的Speed​​tracer浮现在脑海。当然,调整为Chrome并不保证调整对于所有浏览器,但大部分是导致Chrome浏览器对象创建的东西是共同的,因为它是由所有的浏览器实现的JS规范。

As far as tools to combat/diagnose the issue, Google Chrome's Speedtracer comes to mind. Of course, tuning for Chrome doesn't guarantee tuning for all browsers, but most of the things that result in object creation in Chrome are common to the JS spec as it's implemented by all the browsers.

要考虑的一个重要的事情是,内存使用和显存的使用是不一样的。一个最好的做法是确定你的UI的部分被硬件加速,并确保它们很小(即适合在屏幕上一次全部)​​。如果你有在屏幕硬件加速的巨大滚动的部分,你会得到GPU撕裂/瓷砖和laggy滚动。您可以使用的iOS模拟器检测到这个部分。本文介绍的想法简单:http://devinsheaven.com/turn-your-iphone-wacky-and-make-your-iphone-application-better/

One important thing to consider is that RAM use and video RAM use are not the same. One best practice is to determine which portions of your UI are being hardware accelerated and to make sure they're small (i.e. fit on screen all at once). If you have huge scrolling portions of the screen hardware accelerated, you will get GPU tearing/tiling and laggy scrolling. You can detect this in part using the iOS simulator. This article covers the idea briefly: http://devinsheaven.com/turn-your-iphone-wacky-and-make-your-iphone-application-better/

最后,还有在JavaScript一堆真正的公共内存泄漏模式每个工程师都运行到了不时。 IBM有他们的好名单。我不能发布两个以上的链接,因为我是一个的n00b,但你可以谷歌共同的JavaScript内存泄漏,但它可能是第一个结果。

Lastly, there are a bunch of really common memory leaky patterns in JavaScript that every engineer runs into from time to time. IBM has a good list of them. I can't post more than two links because I'm a n00b, but you can google for "Common JavaScript Memory Leaks" and it's probably the first result.