Can anyone link me to a page that describes memory allocations for iPhone apps.
I have heard that you are limited to a sandbox of ~20 megs, depending on the state of the phone, but I can't find the source for this.
It depends on the device you're using. I've found that with an iPhone 3G, when the total memory your app is using goes over 10-14MB, it's vulnerable to crashing. When it hits 20MB, it will crash for sure.
As far as I know, Apple doesn't give any hard figures for the memory that you can use. It's always changing so it's hard to pin down. They recommend that you rely on memory warnings and respond to them appropriately.
iPhone 3GS has a much higher amount of memory available to apps (I've heard that it's around 4 times). Although the iPhone 3GS only has double the memory of the iPhone 3G, a lot of that memory is taken up by the OS. There's very little left for apps to run in. That's why the 3GS will allow apps to use so much more memory.
Also, there can be a lot of memory already in use by the OS. One example is when safari is keeping a lot of tabs open. This is why lots of games recommend that you restart the device if it crashes a lot.
When you're programming, keep an eye on the increase of memory (due to not properly deallocating objects) and the peak memory. This problem is more about real-world testing (on as many devices as possible) and good programming practices.
Here's an article to ready more about how to deal with memory problems:
http://akosma.com/2009/01/28/10-iphone-memory-management-tips/
This tool finds what is the maximum memory capacity of any iOS device. It also can also find at which memory level you received the Low Memory warning.
here is the link: https://github.com/Split82/iOSMemoryBudgetTest
It depends on current device state. Some native iPhone applications can run in background and waste device resources(Mail, Safari, Sms, Phone...) So, it's hard to say how much memory u will get...Ideally, your application should stay within 10-12Mb limit to successfully overcome any memory issues.
I believe it's
Memory warnings at 20MB
Application "crashes" at 30MB
I'm fairly certain I saw this in The iPhone Developer's Cookbook: Building Applications with the iPhone SDK by Erica Sadun (amazing book, btw).
Also: Duplicate -> Maximum runtime memory available in iPhone and iPod?.
Related
Currently i don't have an apple developer account ($99).
I am developing iOS app with searching function in iOS Simulator.
In simulator my app's search speed is not bad, just normal.
But when i check my app for memory leaking with Instrument tool, my app's search speed is too slow and data load speed are also too slow.
I have to load 30 MB data in Start of app.In Simulator it's fast.But in Instruments , it's too slow and also took 6 seconds.
So i am worring about my apps to run on physical devices because of speed.
I would like to know , Is the iPhone physical device faster than Instrument tool's check memory leaking?
In my experience, normal execution on iPhone is much faster than profiling with Instruments. But, that heavily depends on the application and what "instrument" are you using. If your application does a lot of memory allocations, it will be very slow when using Instruments with "Allocations" settings.
But also be prepared, that the iPhone Simulator is usually much faster than the real device. Your desktop CPU is usually x86 and over 2 GHz, but the device's parameters are lower. And also the architecture (ARM) makes the code to be compiled into more instructions than on x86, which also makes it a little bit slower.
Anyway, you really should just go ahead, buy the developer account and test your app on the device, there's no other way to predict the performance. I guess the rule in your situation should be don't guess, measure.
Please dont guess anything test on real device go an buy $99 developer account. iPhone Simulator is usually much faster than the real device. Its a very bad idea to download 30 MB of data at the start. If connection is slow it will take more than 5 min. If your data on device goes more tnan 45 MB apple will kill your applicationa nd free the data. Make sure you are doing in write way.
I am in the last phase of my iphone game development: optimization and performance tuning. My problem is, the game runs quite smooth on iphone 4 and iPad, but it often crashes on iPhone 2 with iOS 3.1.3 due to low memory.
I have gone through all the memory leak detection / clean up processes, and the Xcode instrument shows no leak except those from system library (see following screenshot). I also use "autorelease" rarely.
(bigger picture: click here)
I also profiled my application using "CPU Sampler" and "Allocations", but is a little confused by the result. This is the result from "Allocation" benchmark:
(bigger picture: click here)
This is the result after one game. As you can see, the "Live Bytes" is only 3.93MB, which shouldn't be a big deal (according to my understanding) -- but the game often crashes at this time on iPhone 2, ios 3.1.3 .
I also did a "CPU sampler" benchmark, following is the result:
(bigger picture: click here)
What confused me is, the real memory shows "22.32MB" and the virtual memory is more than 100MB, which is dramatically different from the result of "Allocation benchmark".
I am also confused by the fact that, my iPhone 3G, running iOS 4.1, even if it has almost exactly same hardware spec with iPhone 2, can run my game very well. It's slow and not as snappy, but it rarely crashs.
So my questions are:
What else I can do to identify the low memory issue on iphone 2?
Are the leaks from system libraries on the "Leaks" profiling result a problem?
Why "CPU sampler" and "Allocation" shows different memory foot print? Did I read them correctly?
Why iPhone 3G runs a lot more smoother than iPhone 2G? Is it because the newer iOS version (4.1 vs 3.1.3)?
1. What else I can do to identify the low memory issue on iphone 2?
Run your app in iOS simulator and use Hardware menu item "Simulate Memory Warning" item to trigger Out-Of-Memory events in places, which you suspect to crash.
Instrument your app in real device, but before launching it start as many other apps as possible to reduce amount of available memory. While running your app, switch every now and then back to app grid to (re)launch other apps. This way you will make system generate genuine Out-Of-Memory events, but you can't choose which app will receive them.
You could generate OOM events by yourself, but then you would be running a different application. Might be useful, while developing, but not recommended when close to release. Very annoying to debug bugs caused by debugging "helper" routines...
2. Are the leaks from system libraries on the "Leaks" profiling result a problem?
They could be side-effects of your code. Look around which part of your app might be starting that system service and whether you release / cancel / close everything.
3. Why "CPU sampler" and "Allocation" shows different memory foot print? Did I read them correctly?
No idea, but would like to know :)
4.Why iPhone 3G runs a lot more smoother than iPhone 2G? Is it because the newer iOS version (4.1 vs 3.1.3)?
iPhone 3G has better, faster and more hardware than iPhone2. As result, apps seem to run faster... which can be a problem, if your app runs too fast in faster hardware. Making sure your app runs "just right speed" regardless of hardware is a different question.
I am currently working on a personal iPhone project that is very audio and graphic-intense and I have therefore been quite conscious of how much of a footprint my application has (in terms of both memory usage while active and/or in 'multi-tasking mode' and how much the size of application is) as Apple sub-consciously gets into my mind and has drilled in the fact the iPhone has limited memory and capacity - and I was curious if any of you guys had any solutions that could help me keep down the usage of my application - I've open up Instruments and configured some aspects although this primarily appeals to me as a performance utility). I have also been testing on my device as I cannot stand the simulator...
As long as you are properly releasing objects that aren't being used, you should be fine. If you are loading large images and audio files, then your app will require more memory to handle those, so alloc/release those as they are needed.
Also, debugging memory issues on the Simulator just wont work, so don't rely on it for testing memory issues.
I know this has something to do with Instruments, but well it's kind of confusing and searching for Instruments on Google doesn't help much.
I'd like to know how well my app runs, like how much memory it uses. I just don't know where to find something like:
"As close as we can tell from the simulator you'll app will currently be using xx MBs of RAM on a real iphone device."
I need help on how to get this information.
You shouldn't test your memory usage in the simulator for a number of reasons, some of which are:
The simulator is running on your computer, not the phone, so the maximum amount of memory is the same as the amount of ram you have installed in your Mac.
The simulator, and your app when build with the simulator SDK, do not use the same libraries as they would on the device, and as a result, could use a different amount of memory.
However, if you can run on a device, you should use the Memory Monitor and Object Allocations instruments in Instruments to monitor your memory usage.
You should use the Run/With Performance Tools/Object Allocations. The graphs will show you the memory used.
And then you check the box "Created and Still Living" to know what objects are in memory.
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.