Recognise an out of memory crash (IOS) - iphone

Our apps are live on the app store.
I wish to recognise crashes of out of memory that some users are getting.
I understand there is no way to 100% recognise an out of memory crash.
Is there any way to recognise these crashes(with a pretty large probability) by doing some logic in the applicationDidReceiveMemoryWarning? (I am not talking about finding it in xcode during development time, i am talking about code that will recognise the out of memory crash from actual users and will log something to file)

While I was looking for any service or library that give me OOM tracking, I could only find this article from Facebook engineering:
https://code.facebook.com/posts/1146930688654547/reducing-fooms-in-the-facebook-ios-app/
The idea is to deduce the reason why the app needs to be launch, checking different aspects (like if the app was at background, if there is an app/OS update,...).
Discarding all the other possible reason that can force the previous app exit, you can know if the reason is a background out of memory or a foreground out of memory.
It would be nice to have a library that implements the Facebook article procedure. But nowadays I couldn't find any, probably there is some reason that make this difficult or may be impossible to add it as an sdk.
If anyone knows any service, please share it with everyone with a comment or a new answer.
Edit:
I have discovered this github (https://github.com/jflinter/JRFMemoryNoodler) with an implementation of the Facebook post procedure. I haven't tried yet, but we will deploy it in our apps to try it.

Look out for the applicationWillTerminate message in your app delegate. This is called if you app is terminated by the system (due to e.g. low memory), but not if the user leaves the app in the usual way by pressing the home key. Note: if your app is in the background and memory runs out, your app gets killed without any messages being sent to it.
YMMV, especially with older versions of iOS, and it's worth researching to ensure that the above is accurate.
The images at this blog post are quite informative (although slightly dated).
For more info, see How to know whether app is terminated by user or iOS (after 10min background)

Firstly Analyse your application by clicking on the Product at the top menu bar of your Xcode and click on Analyse section it will show you the number of leaks on in the application and can take you to the place where leaks occurred. This is how you can find the memory leak and rectify it.
Secondly it above does not worked then see to the view controller where crash occurred and check whether you have left any object to release.
Hope this might help you to resolve your problem.

Related

automatic app testing in xcode

Currently I'm testing an app that I've written with ios 4. I've spent a good bit of time looking for memory leaks and that side of things seems o.k.
I have a problem where the app seems to "randomly" quit after going from one view to another. Sometimes this will happen after a minute or 2 and sometimes it won't happen at all. Because of this it's really very difficult to determine where the flaw in my application is and under what circumstances because my observations of whats going on is subjective. Also it can get very annoying very quickly sitting there hitting buttons until something happens and then trying to remember the sequence of your actions.
What would be a good method to hunt down the cause of this seemingly randomly occurring problem?
For example,
I remember speaking with QA engineer before and he spoke of tools that he used to automate a user using an application. He'd leave it running over night and then in the morning he could examine what combination of user actions and under what circumstances a problem occurred.
Are there such tools available for testing iphone applications? Ideally what I'd like to see is a report of
action a
action b
action c
= everything ok.
action a
action c
action b
= there was a problem.
There's also fonemonkey: http://www.gorillalogic.com/fonemonkey
As for random crashes... I am tester, not developer, and random crashes are usually one of the topics I examine more thoroughly on every iphone app. My favorite scenarios are: leave the phone for 2 min, for 10 min, and switch apps (on iOS 4). In all cases it's better to use a real phone (and the older the better), not a simulator (some crashes never happen on simulator). Commonly nested views are affected (e.g. get to some view, let phone sleep, click "Back" button to return to previous view - crash). Usually developers say that incorrect retain / release, autorelease while another object holds pointer, and other memory issues are to blame. Also Device Logs (which will have crash report) usually can pinpoint problem pretty accurately.
Hey.
Instruments by Apple. Apple reference.
Instruments has its limitations and drawbacks, but just try it. It may be confusing at the begging so try to follow tutorial, or some other.
Check out running the app with zombies enabled. Also, instruments in Xcode is very helpful.

How do YOU handle crashes in your iPhone apps?

If been looking around the web and can't seem to find any good solutions to sending allowing your user to submit bug reports from your iPhone app.
How do you handle crashes and exceptions?
Do you send the error user-data to a server,
grab a log file from somewhere and attach,
or do you ignore it and pretend it never happened?
Anybody got any experience with this?
Update
I am aware of how to prepare you software testing it with Static Analysis, Leak Detection, User Testing etc.
But errors might still happen when a user (mis)using my software. Always assume your user is trying to break your software.
What I want to figure out is how (I, or rather the app) can provide me with useful data when/if errors happen. As they do even in top quality products – like my own ofc. :)
I'm looking anyone that has experience with allowing the use to send error reports, stack traces, logs etc. to see how they handle the problem.
Some people use built-in analytics like Flurry which will post exception data to Flurry's website which you can review later.
Also, Apple has a "crash log" reporting area on iTunes Connect, but I'm not sure if it works since I've yet to see something come through and I kinda doubt each and every person has run my apps flawlessly. Not saying I write poor code (hopefully), but not every device is created equal either so I have to imagine it has crashed at least ONCE. There's always the option of logging and sending to a server later though.
Most of the time though, if you give users your e-mail address within the app itself (like on an instructions or about screen), they will e-mail me about any issues. That's a little bit nicer since it gives you a chance to correct the issue before they hit the review forms on iTunes.
You can also try BugSense. It's free, realtime, error reporting for iOS
PS: I am one of the founders.
Crashes most of the time comes with problems of memory management. To test memory leaks and find in your code on to what areas you were leaking a memory. Use the Instruments if your using XCode.
In your XCode go to Run -> Run with performance tool -> Leaks.
You can check everything here when it comes to memory allocations.
Note: To avoid crashes, make sure you released objects correctly and check your scheduled timers as well.
Regards,
ZaldzBugz

integrating twitter in my iphone application

i am integrating twitter in my iphone music application.i.e when a user clicks a song and then he click on the twitter tab the login page of twitter should be opened and when he enters his username and password and then he clicks on the post button the song name and the comment he has entered in the textview should be posted to his twitter id.
the problem is that when i am clicking on the post button on the command it is showing as posted but then suddenly the program stops giving me an error of “EXC_BAD_ACCESS”.
Please help in solving the problem
You can use Instruments with the Zombie template to find the solution to this bug. You're probably trying to message a deallocated object.
EDIT: On the WWDC Session video's there is a video with a nice and good explanation how to find these kind of bugs. You must be a registered developer to access these videos though.
May I recommend using ShareKit for Social Media integration ?
http://getsharekit.com/ I've used this myself and it's by far the easiest solution of integrating social media interaction in your app.
Hope this helps.
I wrote a blog that gives several approaches to finding EXC_BAD_ACCESS
http://loufranco.com/blog/files/debug-iphone-crash-EXC_BAD_ACCESS.html
Here is what is happening -- Your program is running a line of code that tries to read or write to a memory location that hasn't been mapped for your application. The most likely reason for this is that you have a bug that is corrupting memory or you are sending messages to deallocated objects.
It is very likely that the line of code that is running is not the bug -- it happened sometime before this.
I strongly recommend a Build and Analyze and scan-build, because it finds these kinds of bugs a lot. It will likely flag a lot of code in your project -- you should address each problem because it's likely a real problem that will cause a leak or crash.
After that, try suggestion #4 in the blog which will instruct the simulator to never deallocate any objects -- once an object is in the state where it would be deallocated, it will warn you if anyone sends it a message. This would have caused EXC_BAD_ACCESS, but now gives a good description of what is happening.
Obviously, you need to turn this off in the real application (or have a lot of leaks).

iPhone: Can my Leaking App harm other apps?

So, I finished writing my first iPhone App, and I have sent it out to a group of beta testers.
Everybody is happy, except for this one guy who noticed that after having run my app, another app is not starting up anymore.
Not knowing too much about memory management, I started looking at the Leaks graphs in Instruments, and noticed, that there are some leaks going on in my app.
Three questions:
Are leaks always bad? The biggest leak is 15k on a total of 5,1 MB allocated memory.
Will Apple refuse my app because of leaks?
Is not all the memory automatically freed up as soon as my app quits? Could it be that my leaking app is harmful to other apps?
Thanks
Sjakelien
Each app is supposed to run in its own "sandbox," and is by design not supposed to affect any other app installed on the phone. If your reviewer found a case where your app really did affect another app, that's definitely not your fault, although I'd love to know how that was accomplished ;).
My guess is, though, that your reviewer's other app broke completely independently of your app, and he/she is spuriously attributing the fault to your app. Ask him to try to reproduce the problem (uninstall both apps, install the other app, install your app).
what the other two answers say i agree with, however nobody has answered the first question ("Are leaks always bad") directly. i would say that yes they are. it's true that your program can possibly run with them for long periods of time without issue. and the OS should clean up the memory after termination (unless there's a bug in the OS, as said before). but eventually the leak will become an issue for someone at some point when they run long enough. also, even if it doesn't become an issue, it's probably a best practice to always fix memory leaks that you know about.
Any leak that persists beyond the exit of your application is an OS bug, and hence Apple's problem.
It would be unfair to reject your app on this basis.
I don't know if that's any comfort to you.
For the record, my app provokes a leak in mediaserverd.
The leak is a tiny bit smaller in the 3.0GM.
Another incorrect usage of an API crashed mediaserverd.
Also 3.0GM. Nasty. I'd have preferred an error code, however
this could theoretically be used to work around the leak.
It depends on what "memory" you are leaking. Are you using device storage space to cache something? In theory then it's possible that you've used up enough space the other app cannot start because it needs a certain amount of free space.
If we're talking physical memory, then no. When your app is dead it is dead. You could ask them to restart the device and see if they have the same issue.
Apple does approve apps that have memory leaks.
That said, we thoroughly check that none of "our code" leaks before submitting to Apple because users don't like having an app suddenly shut down on them. I say "our code" because there are memory leaks in the framework that are not your doing. Thus Apple approves apps with memory leaks.
Also, I am doubtful your app has adversely affected the user's other app. I have not seen that behavior.

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.