使用Instruments分析内存泄漏-iPhone 4和iOS 5 Simulator之间的巨大差异 [英] Profiling memory leaks with Instruments- huge difference between iPhone 4 and iOS 5 Simulator

查看:75
本文介绍了使用Instruments分析内存泄漏-iPhone 4和iOS 5 Simulator之间的巨大差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Instruments对我的应用程序进行性能分析(查找内存泄漏)时,与运行iOS 5的iPhone 4相比,iOS 5 iPhone Simulator获得的结果截然不同.真正的设备,第二个是与模拟器一起使用的:

When profiling my app with Instruments (looking for memory leaks), I get extremely different results with the iOS 5 iPhone Simulator from those I get with my iPhone 4 running iOS 5. The first picture shows the results from the profiling with the real device, and the second is with the simulator:

真实设备:

iOS 5模拟器:

在两种情况下,此配置文件都在应用程序中占据相同位置:在rootViewController的视图生命周期中完成viewDidLoad.我已经等了他们两个,以便总分配的内存稳定下来.正如您在设备图中看到的那样,大约在00:10发生一些极端的波动,这些波动在模拟器中不存在.在实际设备上,总分配内存在00:08左右从1MB跳到3.5MB,然后又回落到1.5MB,最后跳到4.74,在此稳定.为Simulator分配的内存更加线性,可以稳定且迅速地上升到大约2.35 MB,并在此稳定.

This profile is taken up to the same point in the app in both cases: completion of viewDidLoad in the rootViewController's view lifecycle. I have waited in both of them for the total allocated memory to stable out. As you can see in the device graph, there are some extreme fluctuations occurring at about 00:10, which aren't present in the Simulator. On the real device, total allocated memory, at around 00:08, jumps from 1MB to 3.5 MB then back down to 1.5 MB and finally jumps to 4.74, where it stabilizes. The allocated memory for the Simulator is much more linear, with it climbing steady and quickly to around 2.35 MB where it stabilizes.

要注意的另一件事是设备上存在2.25 MB的已分配内存,但malloc中的Simulator和CFNumber中没有700+ KB.由于我对使用乐器和配置文件还比较陌生,因此我不确定这是否正常.快速的Google搜索并没有确定的结果. 2.25 MB和700 KB可以弥补内存分配上的差异.为了平衡起见,在模拟器测试中存在更多的malloc条目,而这些内存具有不同的内存,而在设备测试中则没有.

Another thing to note is the presence of 2.25 MB of allocated memory present on the device but not the Simulator from malloc and 700+ KB from CFNumber. As I am relatively new to using Instruments and profiling, I'm not exactly sure if this is normal. A quick Google search turned up nothing definitive. That 2.25 MB and 700 KB more than make up for the difference in memory allocation. To balance things, there are more entries for malloc with different amounts of memory present in the Simulator test not present in the device test.

我还发现,当将第二个UIViewController推入UINavigationController堆栈时,在实际设备上分配的内存跳至约8.5-9 MB,而在上端仅约4.5至4.5兆字节 tops 模拟器.

Also, I found that when a second UIViewController is pushed onto the UINavigationController stack, allocated memory jumps to about 8.5-9 MB on the real device, but only about 4.5 to maybe 4.5 megabytes tops on the Simulator.

我知道可以预期该设备的性能与Simulator会有很大不同,但是由于两个设备上都运行了相同的代码,所以内存分配应该不是很相似吗?我将了解这是否是性能分析,但是对于内存分配,数字似乎应该非常相似.任何人都可以阐明这是否正常吗?

I know it is to be expected that the device would perform much differently from the Simulator, but should memory allocation not be pretty similar because the same code is being run on both devices? I would understand if this is a performance profiling, but for memory allocation, it seems that the numbers should be pretty similar. Can anyone shed some light as to whether this is normal or not?

推荐答案

这种现象是可以预期的.从技术上讲,当您使用模拟器运行性能分析时,您将基于台式机的硬件来测量统计信息.即使您只是对分配进行概要分析,也不能指望它们能以类似的方式工作,因为许多软件优化/算法/等都基于运行的硬件.

This behavior is to be expected. Technically, when you run profiling with the simulator you are measuring stats based on your desktop's hardware. Even if you're just profiling allocations you can't expect them to work similarly because a lot of software optimizations/algorithms/etc are based on the hardware it's running on.

不幸的是,Apple没有iOS 模拟器.不过,最好还是使用设备进行性能分析,因为仿真器仍然不可靠且运行缓慢(例如Android仿真器).

Unfortunately, Apple doesn't have an iOS emulator. You're better of profiling with the device though, as emulators tend to still be unreliable and slow (e.g. Android emulator).

这篇关于使用Instruments分析内存泄漏-iPhone 4和iOS 5 Simulator之间的巨大差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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