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.
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.
Any thoughts on why this code runs slow on device but fast on simulator in iphone, I am making a game in cocos2d, and I am moving an object from one place to another , throught CCTouchBegan , CCTouchMoved, CCTouchEneded (ccp function) and after that I take the action on it,
can any buddy tell me what is the main issue to solve this problem,
The simulator is a simulator not an emulator. All the simulator really does is provide a window for running an iOS app. You'll notice that when you build for the simulator, the system architecture is set to i386. You're compiling for the Mac when you use the simulator. There's no memory restrictions, sandboxing etc. In fact, I think your app even shows up as it's own process.
That's why when you run it on the device, you get hammered. You just have to work on optimizing your code. The simulator is terrible. Just use your device for debugging, it'll save you the confusion. If you post your code, we might be able to help you speed it up.
Happy coding.
The basic hardware of the computer on which the Simulator runs and that of an iOS device are very different, from CPU clock speed, to instruction parallelism, to branch prediction, to cache size, to memory bandwidth, to memory available. The possible compiler optimizations might also be different, given the different ISAs. It's not uncommon for general code to run an order of magnitude faster on the Simulator on a Mac than on an iPhone.
There can be many reasons like (also) #simulator vs actual device
Low Memory can be the first problem as in your actual device as you will install different kinds of huge applications but in case of simulator you will not install t.
Low power problem as the actual device will be powered by battery and not like simulators which get constant power all the time.
Other application interfering with your application run cycle but in simulator you will hardly run any application while you are testing your application.
You cannot see the UserInterface(UI) as clear in your MAC as you can see in your actual device, so which appears correct may not be actually correct.
Application interfered by calls, in simulator this type of interference will never happen.
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?.
Also, is running an app in the simulator sufficient to get a ball park estimate or will I get very different values from running on the device?
The default (and a very good) tool is Instruments, which comes with the SDK. Here is Apple's doc on Instruments.
Memory usage on the simulator is generally the same, although if you are using OpenGL ES, the simulator has significantly less memory errors (and better performance) on the simulator. So the general rule of thumb is: it's ok to test your memory on the simulator, except for OpenGL ES usage.
When you run the application using Instruments (Object Allocations) in the simulator, that should give you a very accurate memory usage picture.
Is Activity Monitor (a.k.a. Memory Monitor) the only tool in Xcode Instruments that can measure the total app RAM usage of an iPhone app running in Simulator? Just that line showing momentary wired RAM?
And how accurate is that versus iPhone hardware, especially given OSX paging i/o to VM?
I'm seeing 7-8MB wired RAM figures for just the default Xcode iPhone project templates (other than OpenGL) compiled and running. At the same time Object Allocations shows well under 1MB for all objects.
Nope, there's a much better way to do it.
Go to the Run menu and select Run with Performance Tool then Object Allocations.
This will start Instruments and will show RAM usage. It's also useful for detecting memory leaks if you choose Leaks instead of Object Allocations.
I would agree, since the Simulator is just an "API simulator", the behavior you see is going to be at least somewhat dependent how OS X manages memory. And the restrictions are obviously different, for example you can exceed 128 MB of ram, or even 256 MB, which obviously isn't possible on any current iPhone or iPod Touch (at least, as of this writing...).
I've still found it useful in OpenGL for making sure textures and other items are properly deallocated, but beyond that, it's just a rough guideline.
However, if you want to see memory usage on device, there's a simple enough solution. Just target Device in Xcode, and go to Run > Run with Performance Tool > Object Allocations, then the build will be sent to the device and the Object Allocations tool will pop up next to Xcode and show on device memory usage.