Profiling memory leaks with tools - a huge difference between iPhone 4 and iOS 5 Simulator

When profiling my application using tools (in search of memory leaks), I get completely different results with iPhone Simulator iOS 5 from those that I get from my iPhone 4 running iOS 5. The first figure shows the results of profiling using a real device and the second with a simulator:

Real device:

Real device


iOS 5 Simulator:

Simulator

In both cases, this profile applies to the same point in the application: terminating viewDidLoad in the rootViewController's viewing lifecycle. I waited in both of them that the shared memory was stabilized. As you can see on the device graph, there are some extreme fluctuations that occur around 00:10, which are not in the simulator. On a real device, the total allocated memory at about 00:08 jumps from 1 MB to 3.5 MB, then back down to 1.5 MB and finally goes to 4.74, where it stabilizes. The allocated memory for the Simulator is much more linear, while it rises stably and quickly to about 2.35 MB, where it stabilizes.

Another thing worth noting is the presence on the device of 2.25 MB of allocated memory, but not the simulator from malloc and 700+ KB from CFNumber. Since I'm relatively new to using tools and profiling, I'm not entirely sure if this is normal. A quick Google search showed nothing final. This is 2.25 MB and 700 KB more than compensate for the difference in memory allocation. To balance the situation, there are more entries for malloc with different amounts of memory present in the Simulator test, which is not in the device test.

In addition, I found that when the second UIViewController is pushed onto the UINavigationController stack, the allocated memory jumps about 8.5-9 MB on a real device, but only 4.5 to 4.5 megabytes of vertices on the simulator.

I know that it should be expected that the device will work differently compared to Simulator, but should the memory allocation not be very similar, because the same code runs on both devices? I would understand if this is a performance profiling, but for memory allocation it seems that the numbers should be very similar. Can anyone shed light on whether this is normal or not?

+8
memory-management ios iphone instruments
source share
3 answers

This behavior is to be expected. Technically, when you do profiling using a simulator, you measure statistics based on your desktop. Even if you just profile distributions, you cannot expect them to work in a similar way, because there are many software optimizations / algorithms / etc. Based on the equipment on which it works.

Unfortunately, Apple does not have an iOS emulator. You better profile your device, although emulators are generally still unreliable and slow (e.g. Android emulator).

+8
source share

You should always run leaks on your iOS device and never on a simulator. The results you obtained from the simulator will only serve as a distraction, since they are rarely 100% accurate. You will catch a lot of red herring! hehehe

+3
source share
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? 

Technically, the code is completely different. The simulator application compiles for x86 bytecode, while the device compiles for armv6 / armv7.

+3
source share

All Articles