本文介绍了在 Safari 桌面和 iOS 中分析内存的技术?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有哪些建议的技术可以用来发现可能导致 Safari 中 JavaScript/DOM 内存泄漏的原因?有谁知道访问 iOS 内存信息的任何方式?

We're experiencing leaks in Safari (confirmed in Windows and Mac, suspected in iOS). What are suggested techniques for discovering what may be causing memory leaks in JavaScript/DOM in Safari? And does anyone know of ANY way to access memory information for iOS?

如果您在 Safari 中遇到可疑的泄漏,您采取了哪些方法来解决这些问题?

If you have encountered suspected leaks in Safari, what has been your approach to work around them?

推荐答案

安装 iOS SDK 时,还会安装一个名为 Instruments 的实用程序.它可以跟踪各种使用统计信息,包括内存(甚至还有一个泄漏"模板).最棒的是它可以跟踪 iPhone/iPad 模拟器和任何连接的 iOS 开发设备.当然,它还可以用于监视 Mac OS 中的内存使用情况,因此它也可能对 Safari 有所帮助.您可以在/Developer/Applications 中找到 Instruments.

When you install the iOS SDK, a utility named Instruments is also installed. It can track all sorts of usage stats, including memory (there is even a "Leaks" template). The great thing is that it can track both the iPhone/iPad simulator and any connected iOS development device. It also, of course, can be used to monitor memory usage in Mac OS, so it may help with Safari as well. You can find Instruments in /Developer/Applications.

另外一个方便的地方是,每当您将 iPad/iPhone 与 iTunes 同步时,它还会将设备上的所有崩溃报告同步到您的计算机.它们可以在 ~/Library/Logs/CrashReporter/MobileDevice/[Device Name]/中找到.

Something else that is handy is that whenever you sync your iPad/iPhone with iTunes, it also syncs any crash reports from the device to your computer. They can be found at ~/Library/Logs/CrashReporter/MobileDevice/[Device Name]/.

我们在为 iPad 开发时特别发现的一件事是,由于内存问题,它很容易崩溃,特别是在像我们这样的图像繁重的应用程序中.我们了解到的一件事是,仅仅删除一个 DOM 元素并不意味着该元素将被浏览器垃圾收集.我们发现在从 DOM 中删除图像之前将图像 src(或背景图像,如果它是一个 div)设置为一个空字符串有很大帮助.

One thing we found when developing for the iPad in particular was that it was very prone to crashing due to memory issues, particularly in image heavy applications like ours. One thing we learned was that just removing a DOM element does not mean that element will be garbage collected by the browser. We found that setting the image src (or background-image, if it was a div) to an empty string before removing it from the DOM helped immensely.

不确定这些是否有帮助,但希望启动并运行 Instruments 能让您更好地了解所有内存的去向.

Not sure if any of that helps, but hopefully getting Instruments up and running will give you a better idea of where all that memory is going.

这篇关于在 Safari 桌面和 iOS 中分析内存的技术?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 17:24