Memory uses limit on iPhone - iphone

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?

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.

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.

Related

Need more memory for my iPad app

I am working on a mail client on iPad (similar to that of the default app client) and using core data framework as a cache to increase performance . My app uses around 4.5 - 5 MB of heap memory and then it crashes because of memory overflow (detected this using allocation instrument). If I try to reduce memory my performance becomes very slow and sluggish because I am not able to cache my views, data structure (which store folders and all the mails) and tableviews.
I have checked my crashLogs and I see jettisoned written in front of my App which confirms that OS has forcefully closed my App!
I have used instrument to detect these limits. Please find the attached image here
This is a snapshot my recordings just before the app crashes.
I have tested my app on simulator and it stabilizes itself at 6 - 7 MB of heap memory.
Is there any way so that I can ask OS for more memory or avoid crash with a little redesign in my code.
Any suggestions or help would be highly appreciated.
6-8MB of memory should never be a problem. Likely you are either trashing memory or if you are running a debug version and have Zombies turned on, the default is to never delete the zombies. NSZombiesEnabled=YES and NSDeallocateZombies=NO will appear to leak memory as nothing is ever deleted.

Profiling memory leaks with Instruments- huge difference between iPhone 4 and iOS 5 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:
Real device:
iOS 5 Simulator:
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.
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.
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.
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.
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).
You should always run leaks on an iOS device and never on the simulator. The results you get from the simulator will only serve as a distraction since they are rarely 100% accurate. You'll find yourself chasing down a lot of red herrings! hehehe
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.

What is the acceptable value for Live Bytes in Intsruments?

I was running my iphone app, optimizing to reduce memory footprint etc. I see that the live byte shows around 3.5 - 4 MB.
I was wondering what is an acceptable value. Put other way, what is the ceiling I should try to stay under.
Related thoughts, at what level do I get memory warnings, like level 1 level 2 memory warnings?
I am guessing this will have a direct correlation to my iphone device. Is there a matrix we can build depending on the device. I am using iphone 3G
thanks a ton
mb
if you stay under 20MB you should be fine, but as always the less you use the better ;-).
as far as I know the it isn't documented when the memory warnings are triggered, probably because that it is implementation detail and it can change at any moment.
Anyway you shouldn't focus too much on numbers (you don't know other memory consuming processes (safari caching pages, apps in the background using memory), just be a good ios-citizen, make sure you don't leak memory all over the place and your app will be working like a charm.

iPhone Distribution Build Out of memory failure?

I keep getting an out of memory failure when I try to do the distribution build of my app. The app only gets up to a max of 12 megs of real memory when testing it in Instruments. Why is this happening? My app folder is only 18 megs without the build folder in it. Turns to 80 megs with the build folder. But this doesn't seem like a lot compared to other big apps I've seen in the app store. Any ideas?
The size of the application on disk and the amount of memory required by the application when it is running are two different values. The failure you are seeing is relating to the second measurement, not the first. 12MB of memory consumed sounds like quite a bit. While this value is small for the Simulator being run on a machine with gigabytes of available memory (and an on-disk VM system), on the device where 256MB total memory is available it is a much bigger deal. In my experience I've found about 8MB to be an upper limit in memory consumption before things start going south (YMMV).
Is your application responding correctly to low memory warnings? Your app will be notified by the OS when things start to get hairy- not responding to the warnings appropriately can result in your application being preemptively terminated.

How do I see how much memory my iPhone app is using?

How much real memory should my iphone app be using? What's going too high?
Keeping an eye on -(void)applicationDidReceiveMemoryWarning:(UIApplication *)application is definitely important, but if this is game, chances are the assets (notably textures presently on screen) can't simply be deallocated when that warning is received.
If you're a bit on the high side (20 MB +) I would recommend doing a bit of testing. Using Instruments and the Object Allocation tool (Run > Run with Performance Tool > Object Allocations) you can monitor how large your memory footprint gets. Then, try running Safari and fill the pages, then a few games and whatever else you can to get the memory higher, and see how your app performs.
In my testing for a recent release, 24 MB seemed to be pretty safe, and is a number I've heard elsewhere. Once you get above 30 or so MB, chances are your users will start having rare crashes (which happens to be the case for us, verified by crash reports). The higher you go, the more crashes users will see. There's no specific limit though, for the sake of testing I've pushed my app on an iPhone 3G up to 70 MB before, it just isn't likely to work for most, nor for long.
Requesting on the iTunes page that users restart their devices can help, though there's no guarantees it'll be effective.
Also, this is all assuming devices prior to the 3GS / 3rd Gen iPod Touch. If the app merely runs on an older device, it should have no problem on the newer ones (which have twice as much ram, 256 MB).
I think available memory may depend on several factors such as device model, how long it has not been rebooted etc.
You should not rely on some fixed values but instead try to use as little memory as possible and implement -(void)applicationDidReceiveMemoryWarning:(UIApplication *)application in your application delegate and/or -didReceiveMemoryWarning in your view controllers to handle low memory warnings there and free unused memory.