2

What is the amount of memory an app can take before getting kicked by iOS? Does the amount of memory depends on the device version? I have developed an app which is using 30+ mb and its getting kicked on iPhone 2g. Can it work on iPhone 4 or 3GS?

Ideveloper
  • 1,467
  • 4
  • 23
  • 44

2 Answers2

5

My experience with the iPhone 3G is that you should try to stay as small as humanly possible--build your data model with ditchability in mind, because you'll need to ditch. 20mb is bumping against the limit. 25 MIGHT be okay if the phone has been rebooted recently. You'll probably never get 30mb.

By contrast... I managed to prompt a memory warning on my iPhone 4 once, but it was due to an infinite loop bug that downloaded the same image file an infinite number of times. In other words, it took something REALLY drastic to crush the 4. Not that you can ignore memory management completely (a leak is still a leak), but for sure you've got some breathing room.

The 3Gs is somewhere between the two. I don't have one to test on, but I'd expect its performace is more 4-like than 3G-like, because while the on-board memory doubled from the 3G, the OS is still taking up the same space, meaning all of the new memory is yours to play with.

Dan Ray
  • 21,623
  • 6
  • 63
  • 87
  • 1
    Almost all of yours to play with.... the 3GS (and the iPhone 4) both have more features and those features require a bit more memory in the OS. Ultimately, though, it isn't that significant compared to the doubling of physical memory. – bbum Aug 10 '10 at 13:33
  • 1
    Don't forget about multitasking. As applications pile up in memory, the largest ones are terminated first, so it benefits you to keep your memory usage low in order for your application to hang around longer. Also, I've seen a hard ceiling of 30 MB for memory usage per application on the older iOS devices. One step above that results in instant termination. – Brad Larson Aug 10 '10 at 20:04
  • @Brad - Well that's true. Prunability of your data structure is a Good Thing no matter what sort of device you're on, and then just as important is understanding when and where to prune. – Dan Ray Aug 11 '10 at 11:54
  • @BradLarson are we measuring this via "Live Bytes" in Instruments, or is there a more direct/correct measurement that we're all using here? – Dan Rosenstark Oct 25 '11 at 06:05
  • @Yar - Use the Memory Monitor instrument. It gives an honest total reading of your application's memory usage. Object Allocations hides some memory usage: http://stackoverflow.com/questions/5518918/instruments-with-ios-why-does-memory-monitor-disagree-with-allocations/5627221#5627221 – Brad Larson Oct 25 '11 at 14:29
  • Thanks @BradLarson I see now that it only works on the device itself, not on simulator. Great stuff. – Dan Rosenstark Oct 25 '11 at 19:13
  • @Yar - To be fair, memory usage in the Simulator is nowhere near what you'll see on the device, so I don't know if it's even useful to try it there. Aside from obvious overrelease-based crashing bugs, I don't do any memory testing in the Simulator. – Brad Larson Oct 25 '11 at 19:20
  • @BradLarson yes, that's exactly what I'm seeing here. It's useful to see if the right stuff is getting dealloc'ed, etc., but the actual numbers are non-existent or useless on the simulator. – Dan Rosenstark Oct 25 '11 at 20:03
0

All your application's resources on an iPhone 2 should probably stay at less than 20 MB. You can go a little over, but that's it, otherwise the memory warnings will occur. There's only 128 MB of total physical ram for everything - that's the OS as well as your own app.