Memory footprint of an app on iPhone - iphone

I recently had an app rejected from the app store because of Low Memory Exception. The app doesn't leak memory, but its base memory footprint seems to be too high. According to the crash logs sent by apple, it was taking about 14000 pages in the memory (mostly due to huge textures). There were 2 strange things though:
I tested it on 5 devices rigorously before submitting, and never got this crash on any one of them.
I did optimize the textures after the rejection, and brought them to about half the original size (texture memory consumption).
I have no way of knowing how many pages my app is taking now, unless I can reproduce the same crash as apple (which I never could). Is there another way to be able to find out the memory footprint of my app, so that I can be sure that it is optimized enough now.
I did try instruments, but my app crashes when I try to run it through my XCode (must be some problem with my XCode). But it works perfectly when I run it directly on my iPhones/iPods. Any help in finding out the memory footprint of my app on iPhone (if there is something analogous to task manager of windows), would be appreciated.
Thanks
EDIT:
Launching the app from XCode gives the following error in the console:
"Error launching remote program: failed to get the task for process 553."
Launching the app with Activity Monitor gives the following error:
"Target terminated too early to collect data"
EDIT2:
I was able to run my app with Activity Monitor, by using a dev profile instead of distribution profile. But now there are several sections in the Activity Monitor - Physical Memory Used, Real Memory, Virtual Memory. Which one of these do I consider. To sum it up, I need to know which one of these causes the iPhone to throw a Low Memory exception.

XCode -> Run -> Run With Performance Tool -> Activity Monitor.
If the device is connected, Activity Monitor runs on the iPhone/iTouch.

I think you're coming at this from the wrong angle. You're asking how to find the memory footprint without using XCode. I think the question you should be asking is: why can you not use XCode? Presumably that's what you used to develop the application in the first place?
Without XCode you're pretty much flying blind. You say you halved the size of your textures, but how do you know? Does your app release any extraneous memory when it gets a low memory warning? (applicationDidReceiveMemoryWarning:)
First, have you looked at the crash logs from when you run your app from XCode? You should be able to see them in the Organiser in XCode.
I'm not sure there's a single solution to stop your app crashing with XCode. Normally when my iPhone won't allow debugging I just restart xCode and my handset and it starts working again. Restarting XCode sometimes helps. I would also try reinstalling both XCode and the iPhone SDK.

Related

Concerns about testing an app on actual iphone

I would like to start testing my application on my iPhone. However, I have one concern.
What if my app has many memory leaks? If i ran such an app on the iPhone multiple times, wouldn't that result in a crash on my iPhone? i.e memory keeps getting allocated but never deallocated?
should i worry about accidentally creating unnecessary files on my iphone such that each time I run i somehow create a file that i dont delete, and it keeps taking up a few kb of space. I test the app many times and after a while i have no space left on my iphone. can such a thing happen? can testing on an actual device damage my phone???
Thanks!
What if my app has many memory leaks? If i ran such an app on the
iPhone multiple times, wouldn't that result in a crash on my iPhone?
i.e memory keeps getting allocated but never deallocated?
Memory leaks are only a problem as long as the memory is still allocated for your application. As soon as your application closes, or crashes, its memory is deallocated and returned to the OS. If you are running iOS 4 you can double click the home button and close the application to free up memory.
should i worry about accidentally creating unnecessary files on my
iphone such that each time I run i somehow create a file that i dont
delete, and it keeps taking up a few kb of space. I test the app many
times and after a while i have no space left on my iphone. can such a
thing happen?
Yea you should take care to create as few files as possible. However, because all files created by your app are contained in a little sandbox that is associated with your app they are deleted when your app is uninstalled. If you feel like your test app is taking up too much space simply uninstall it and then install it again using Xcode. Although I wouldn't worry too much about this as you would have to create A LOT of large test files before they started filling up your phone.
can testing on an actual device damage my phone???
I highly doubt its possible. That is one of the reasons that apple restricts which API's you can and can't use. If you jailbreak your phone and start doing things apple doesn't want you to do all bets are off.
I wouldn't worry too much about messing up your phone by developing on it. I've never heard of someone damaging their phone doing this and if for some reason you phone starts acting up just restore it in iTunes.
Here's a tip. Use Analyze tool in Xcode. Find leaks and remove them. And check the performance using Instruments. Fix your memory leaks using that as well. Once you do both diligently, there should be no reason to worry about leaks anymore. Your other concerns are a bit unnecessary. If you are using only the public cocoa touch APIs, your device should be perfectly safe :)
Also be sure to clean up any unused resources, etc. When you send it to the background, it only does so much. Make sure you release objects you own, and release the resources. Set autorelease when you can.

Xcode 4 question about object library and NSLog

Two questions. All of a sudden, not sure why, maybe I hit the incorrect hot key, but my Object Library for .xibs in IB now shows NS items used in Mac development and not my typical iOS elements. How do I bring that back?
Second question, if I run an app in the simulator and it says in the console:
Received memory warning.Level = 1
What should I start with in troubleshooting? This is on an old 3G iPhone. Thanks!
regarding your second question: you should start troubleshooting your app for an excess of memory allocation and, if you can, look for memory leaks
maybe you want to look at this topic: iPhone OS Memory Warnings. What Do The Different Levels Mean?
For the first question: restart XCode.
For the second question: If the warning is infrequent and your app is not crashing, don't worry about it. Regardless or warnings or not you should be doing memory testing for leaks and also make sure your app responds to didReceiveMemoryWarning notifications. These warnings are normal and vary greatly depending on what other processes are running.

iPhone Memory Usage Optimization / Performance Tuning

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.

Is it normal for memory warnings to disappear?

I've had lots of problems getting a simple UIImagePicker working (see my other posts), and I've been getting memory warning notifications after taking a picture and before I even get a chance to dismiss the UIImagePicker
Now, however... I've loaded up my app in Xcode today and all is working fine. Can't get the memory warning at all, under the same build settings etc.
My question is.. is this normal? Perhaps it was cleared by an iPhone restart, or XCode restart. Or should I be worried that I've still got a hidden memory warning, only now it's hiding from me?
Thanks!
yes, very normal. memory is used by lots of background tasks on the phone, so it really depends what your email client is doing, whether you're installing apps in the background, and lots more.
It also depends a lot on the device you're testing on too. For example, if you're testing on an iPhone 2G, you'll have a significantly lower amount of memory to play with than if you were testing on a 3GS for example.
Depending on what kind of requirements your app has, and what choices you're making in terms of what to target (3.0 only? 3G upwards, etc) its best to always test on the least capable device so that you can get an accurate idea of how the app will perform on that device.

Game crashes on the actual iPhone but simulator? memory problem?

I have built my first game using Cocos2D. It worked fine on the simulator. But when it runs on the actual iPhone, it crashes. I don know why. Thought it was memory leaks, so i tried to detect, but no leaks found. I tried to increase and decrease frame rate, neither both succeeded. Anyone experienced please help me out. I am really stressed now. If anyone had the same issue please share with me your opinion.
Yours thanksfully.
I've run into similar issues (I also use Cocos, but I don't think this is Cocos specific). The best thing to do is plug-in your iPhone and watch the stacktrace when it crashes (or retrieve the stacktrace after the fact)
This happened to me a lot because the resources between the iPhone and the simulator were not in sync; in other words, some how resources would be available to the simulator (eg: images) but those same resources were not transferred to the iPhone for whatever reason. Sometimes, if I ran 'clean' on the simulator, I would observe the same issue.
It's extremely frustrating to debug these types of issues, but you'll get used to it.
I agree with Dominic - we definitely need more information to be able to help you - do you have the output from the console or the stack from the debugger?
Also, while memory leaks are a Bad Thing, they rarely lead to crashes directly. They will increase the amount of memory used by your app so if you're memory intensive then you might get a problem but they're not the first place I'd look to try to debug this.
Try running the app in Instruments and watch the memory usage graph - then not only can you see the total that your app is using but you can get an idea of which sections of your app use the most and can focus your efforts in reducing it.
Sam
Sorry, but you need to specify more details. How does it crash? What does the error log say? One thing you might look into is the amount of memory, your game consumes. If it uses more than 64 MB on the actual device, the OS will very likely just terminate it. In the simulator on the other hand, your app might use lots more memory without a problem.
I have found tools like Instruments and NSZombieEnabled to be very helpful in tracking down issues such as these.
Without more information, I would try the following steps:
Delete the app from the device and simulator (using the tap-and-hold technique to make your icons jiggle) and reinstall it. Sometimes a setting (or lack of a setting) in the user defaults will cause a crash, and those don't get wiped out unless you delete and re-run your app.
Also try the "simulate memory warning" option in the simulator and see if that gets it to crash.