-1

I noticed that there are differences in memory management in iOS simulator and iOS devices. Sometimes on the device there is a crash because of trying to access an object that doesn't exist any more, while on the simulator it doesn't appear (object still isn't collected).

Now I have a problem, when on the simulator view doesn't appear (probably gets deallocated), while on the device everything is okay. I'm guessing it also has something to do with the memory management.

Where can get a deeper understanding of the differences between the memory management on the device and on the simulator? And also other device/simulator differences.

P.S. I'm aware of the similar question: Difference of memory organization between iOS device and iPhone simulator But the answers on this question don't give an understanding what's happening, just the information about the memory warnings.

Community
  • 1
  • 1
Sergey
  • 47,222
  • 25
  • 87
  • 129
  • 5
    you shouldnt treat device and simulator differently — if it crashes on one of them it means your app is faulty on both. – vikingosegundo Sep 05 '13 at 09:47
  • no they aren't equal and should be treated differently. e.g. with store kit. -- the device is the master – Daij-Djan Sep 05 '13 at 13:15
  • 1
    The point is that if the program is broken in one case then it doesn't matter what makes it work in another case. It still has to be fixed. – FreeNickname Sep 05 '13 at 14:06

4 Answers4

4

@FreeNickname's answer is exactly correct. You have a bug, and you're just happening to see it in one configuration. There are couple other things to keep in mind:

  • A common reason for things to crash on one platform but not the other is failure to maintain thread safety. iOS devices have 1-2 cores. Macs have many more than that. Things that run in parallel in the Simulator may become serial or almost serial on the device.
  • Sometimes the problem isn't threading, but just regular async. Macs are much, much faster than iOS devices; not just because they have more cores and memory. The network connection is usually faster, too. Disk access is faster. Everything is faster. So if you have a race condition, it can manifest completely differently on the two platforms.
  • The best first line of defense against memory errors is ARC. It is strongly recommended.
  • The static analyzer is your second line of defense after ARC. Make sure you are running it regularly and resolving issues it finds. It should go without saying that you should make sure your program has no compiler warnings.
  • Manual threading (NSThread/pthread) can also lead to these kinds of problems. GCD/NSOperation, is recommended. In either case, it is recommended that a given object only be modified on a single queue (usually by having a background task do a calculation/fetch/task, but then posting the result back to the main queue to store it).
  • Your comment "(object still isn't collected)" suggests a possible misunderstanding of ObjC memory management. There is no garbage collector in Cocoa. Objects are deallocated at deterministic times; as soon as the last retain on an object is removed, it is immediately deallocated. This may be delayed with autorelease pools, but it is still deterministic.
Rob Napier
  • 286,113
  • 34
  • 456
  • 610
2

I think what you want is not a difference between a Simulator and a device, but an understanding of how memory management works. Because if an error occures anywhere, either on a device or in simulator then there is an error and you have to fix it. This manual is rather short, but it explains all basic rules you need to know to avoid errors. iOS Memory Management Programming Guide

FreeNickname
  • 7,398
  • 2
  • 30
  • 60
1

Memory management is the same on simulator and on IOS. The only difference that on simulator you have 4GB virtual memory and on device - only real RAM.

If you will try display deallocated view, app will crush on both simmulator and device.

So the main difference, that if you have memory leaks in app, on device you will get know about that much earlier.

Cy-4AH
  • 4,370
  • 2
  • 15
  • 22
0

The above answers about memory management are correct. But there are small difference of behaviour between simulator and physical device that are hard to notice sometimes.

Here are few things that could be the possible answer to your problem.

If you are trying to access resource files (images, sounds etc) in your program, make sure that you are case sensitive (uppercase / lowercase letters). The simulator ignores the case sensitivity however the program crashes on device.

Example: If you have "Image.png" file in your project and you used "image.png" to access it in your program, the simulator may load the file but it will definitely crash on device.

If you have a higher resolution file, it might load in the device but doesn't appear on the simulator or vice versa (depending on your computer as well).

You can also check the Internet connectivity on both devices, maybe your program is using external links and your computer isn't connected.

Naveed Abbas
  • 1,157
  • 1
  • 14
  • 37