测试 iPhone 应用程序时,仅使用 Leaks 工具就足够了吗?
我即将完成我的第一个 iPhone 应用程序,我想知道是否有一组步骤用于检查应用程序的内存泄漏、性能等?
使用 Leaks 仪器进行检查就足够了吗?
是否需要进行一系列测试?你们有什么教程/文档可以指点我吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
与“泄漏”一起运行很重要。我不知道最终测试的教程/清单,尽管类似的东西会很方便。我要补充的几件事:
1)一定要使用实际硬件进行测试,而不仅仅是模拟器,以确保您打算支持的所有硬件上的性能都是合理的。根据我的经验,模拟器无法让您准确感受设备的性能,并且旧硬件和新硬件之间可能存在显着差异(极端的例子是 iPhone 4 与 Gen1 iPhone)。例如,在我的一个应用程序中,我生成了一份 1 页的 PDF 报告。在 iPhone 4 甚至 iPad 上,大约需要 1 秒。在第一代 iPhone 上,相同的代码需要接近 8 秒。我无能为力来加快速度,但很明显我需要添加一个进度指示器,让用户知道应用程序没有被冻结。这是我不会注意到仅使用模拟器和/或最新硬件运行的事情。
2) 您可能想花一点时间运行 NSZombieEnabled。即使当前没有明显的问题迹象,这也可以发现可能潜伏在幕后的内存问题。更多信息:
http://www.cocoadev.com/index.pl?NSZombieEnabled
Running with "Leaks" is important. I'm not aware of a tutorial/checklist for final testing, though something like that would be handy. A couple things I would add:
1) Be sure to test with actual hardware and not just the simulator to make sure that performance is reasonable on ALL hardware you intend to support. In my experience, the simulator does not give you an accurate feel for the performance of the device and there can be significant differences between older and newer hardware (the extreme example being iPhone 4 vs. Gen1 iPhone). For example, in one of my apps, I generate a 1-page PDF report. On iPhone 4 and even iPad, it takes about 1 second. On Gen1 iPhone, the same code takes close to 8 seconds. There wasn't much I could do to speed it up, but it was clear I needed to add a progress indicator to let the user know that the app was not frozen. This is something I would not have noticed running with just the simulator and/or the latest hardware.
2) You might want to spend a little time running with NSZombieEnabled. This can find memory issues that may be lurking behind the scenes even if there is currently no visible sign of trouble. More information:
http://www.cocoadev.com/index.pl?NSZombieEnabled
使用 Leaks 工具进行测试应该是您策略的一部分,但不是全部。您将需要从多个角度测试您的应用程序。
我的测试策略倾向于首先关注功能测试,然后是性能测试,然后是最后一轮功能测试。如果代码中某处存在崩溃错误,那么调整性能就没有什么意义,除非该崩溃是由于某种资源耗尽造成的。
锤击应用程序,尝试在您能想到的每种条件下运行每个选项,使其突破。如果通过了,我通常会使用“疯狂的猴子破解”测试,我会尽可能快地敲击屏幕上的随机按钮和区域,看看是否会暴露任何进一步的崩溃。
直到那时我才转向仪器。使用时间分析器和内存监视器仪器在设备上运行应用程序(不应在模拟器中进行性能调整)。寻找性能热点和内存峰值以及内存累积。执行此操作时,请重复之前用于功能问题的相同测试。
一旦处理完热点和明显的累积情况,您就可以进一步对内存进行更细粒度的检查。实际上,我更喜欢使用对象分配工具及其新的堆快照分析功能,而不是泄漏工具来查找细微的内存累积和泄漏。泄密工具往往比较保守,可能会错过一些进展。 Nathaniel 指出 Bill Bumgarner 的出色关于该主题的帖子。
对象分配工具及其堆快照与 UI 自动化工具结合使用时特别强大,您可以在应用程序的某些部分中执行数百或数千个循环的测试,以使得即使是最小的内存积累也能脱颖而出。我现在开始做更多此类测试。
我认为最好是在实际中看到这一点,而不是在文本中描述,因此我建议观看我的“测试”和“性能调整”课程的视频,作为我的 iTunes U 上的高级 iOS 课程。我演示了这些工具中的每一个,以及在提交 App Store 之前测试我自己的应用程序时如何使用它们。我的课程笔记(位于VoodooPad 格式)也详细描述了这一点。
Testing with the Leaks instrument should be part of your strategy, but not all of it. You will want to test your application from multiple angles.
My strategy towards testing tends to focus first on functional testing, followed by performance tests, and then a last round of functional tests. There's very little point in tuning performance if you have a crashing bug somewhere in your code, unless that crash is due to resource exhaustion of some kind.
Hammer on the application to try and make it break by running through every option under every condition you can think of. If that passes, I usually employ my "crazy monkey on crack" test where I hammer random buttons and areas on the screen as fast as I can to see if I expose any further crashers.
Only then do I turn to Instruments. Run the application on the device (no performance tuning should ever be done in the Simulator) using the Time Profiler and Memory Monitor instruments. Look for both performance hotspots and memory spikes, as well as memory accumulations. Repeat the same sort of testing you used for functional issues earlier while doing this.
Once you deal with the hotspots and obvious buildups, you can step down to a finer-grained examination of memory. I actually prefer using the Object Allocations instrument with its new heapshot analysis capability to the Leaks instrument for finding subtle memory buildups and leaks. The Leaks instrument tends to be conservative, and can miss some buildups. Nathaniel points out Bill Bumgarner's excellent post on the subject.
The Object Allocation instrument and its heapshots are particularly powerful when combined with the UI Automation instrument, where you can do hundreds or thousands of cycles of testing within parts of your application to make even the tiniest memory accumulation stand out. I've started to do more of this kind of testing now.
I think it works best to see this in action rather than described in text, so I'd recommend watching the video for my "Testing" and "Performance tuning" classes as part of my advanced iOS course on iTunes U. I demonstrate each of these tools and how I use them in the testing of my own applications before App Store submission. My course notes (in VoodooPad format) also describe this in detail.
Leaks 工具可以发现许多可能的泄漏,但不是全部。观察您的总内存分配并确保它在应该的时候减少。阅读 bbum 的堆快照分析案例研究:
http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using -heapshot-analysis-to-find-undesirable-memory-growth/
并通过“构建和分析”命令运行 Clang 静态分析器(如果您从一开始就没有这样做)。
The Leaks instrument catches many possible leaks, but not all. Observe your total memory allocation and make sure it declines when it's supposed to. Read bbum's heapshot analysis case study:
http://www.friday.com/bbum/2010/10/17/when-is-a-leak-not-a-leak-using-heapshot-analysis-to-find-undesirable-memory-growth/
And run the Clang static analyzer, via the Build and Analyze command, if you haven't been doing so from the getgo.
你应该为你的应用程序模拟低内存,看看它的反应如何,被 iOS 杀死可不那么有趣,因为你消耗了太多内存。如果您仅在模拟器上进行开发,则很容易错过,因为它在内存方面似乎相当宽容。
You should simulate low memory for your app to see how it reacts, its not so fun to get killed by iOS because you are consuming too much memory. If you develop only on a simulator its easy to miss since its seems quite forgiving when it comes to memory.
只需确保在需要减少内存泄漏时释放对象即可。
检查此链接以了解有关仪器的信息。
http://developer.apple.com/库/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html
Just make sure you release the objects whenever it is necessary to reduce memory leaks
Check this link to know about instruments.
http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/InstrumentsUserGuide/Introduction/Introduction.html
首先构建您的应用程序,但不要这样做,现在单击 XCode 顶部菜单栏上的“运行”,然后单击“使用性能工具运行”并选择“泄漏”。
您将看到新窗口,您可以在其中查看应用程序使用的实时字节以及内存泄漏的位置。内存泄漏将以红色标记显示。
如果执行此操作时发现任何问题,请随时询问。
First of all build your app but don't it, now click on the "Run" on the top menu bar of the XCode and then click "Run With Performance Tool" and select "Leaks".
You will see the new window where u will be able to see the Live Bytes used by your app and where memory is leaking. Memory leaks will be shown by red mark.
If find any problem while doing this, feel free to ask.