Often, when a lot of applications were opened before my application I get "didReceiveMemoryWarning" and then, after a while iOS usually closes my application.
This is actually become a noticeable problem.
I have read so much so much consider to "didReceiveMemoryWarning" for the last few days. Including posts here. Unfortunately no solution found.
I know that I have to release any memory on this warning and bla-bla-bla…
The problem is that right after application start there is nothing to release. I have one UIViewControlled in memory with AdMob 4.0.2 banner and one own container that serves application data - which is a few records in NSMuttableArray.
Right after start my application takes 1.3 Mb – according to Instruments and at this initial state my application was not working and I definately know no memory leaks.
What is wrong?
I see that some of the heavy games can be started with no problems, but in the same time my application in this case gets "didReceiveMemoryWarning" and is closed.
Is there a way work in normal way in this situation.
Is there some tricks?
Thanks in advance for your suggestions.
Where are you allocating the NSMUtableArray? I think it's being allocated often! (Just a probability...) Do you releasing the NSMutableArray?
Related
I have nearly completed development on my app. The app is quitting at random points and the user interface freezes/loads very slowly. The app was made without ARC and I am just getting started with using Xcode Instruments to fix memory issues. I am considering moving the entire project to ARC, but don't know if that will help. Also, many of the processes that Instruments Allocations is picking up don't appear to be taking up too much memory.
I need to figure out the best way of improving the efficiency of my app. I have little knowledge in the area and have read a variety of tutorials on how to do certain things to improve efficiency, I just don't know where to start. Should I convert to ARC? Should I focus on using the Allocations/Leaks/Profile Instruments from within Xcode? I know its probably specific to my app, I just don't know where to begin. Any general advice would be great! Thank you all!
Changing to ARC is not got to help you, instead of this focus on Allocations/Leaks. Also try to optimize you code if doing something again and again. Also if you are using synchronous web-service call it also freezes the app.
If your app is not something very large, I advice you to move the project to ARC. Using ARC solves lots of developer mistakes in terms of memory.
When we have ARC, why not use it?
And the other thing is, if there are time taking processes. Perform them in a background thread.
I am new here . Sorry if I this question is being repeated but I have a slightly different issue than the others.
My app crashes randomly after certain amount of time interval without any error logs or stack trace. I suspect it's an memory issue . I have the following questions :
1.) How to get stack trace (I have tried NSZombie enabled and NSUnacughtExcpetion handler) but didn't worked
2.) I get Memory warning frequently in my app. How do I confirm whether it's the prime suspect for the above issue? (I have used Leaks, my app crashes when it has just 4Mb usage so I am not quite sure whether memory leak is causing it my app to crash. I know certain application which take heap memory more than 4MB .)
3.) What is the upper limit for Memory leak for an application in iOS before app crashes ?
4.) Would ARC help me in this situation ?
Also, I have tried to debug issue using NSLog statements but since it crashes randomly , it would be hard for me to detect the root cause using this technique.
Any ideas would be or help would be really appreciated
My app crashes randomly after certain amount of time interval without any error logs or stack trace. I suspect it's an memory issue.
To confirm that it's a memory issue, sync your device with iTunes,and look in ~/Library/Logs/CrashReporter/MobileDevice/ for a files with LowMemory in their name. If you see (jettisoned) next to your app name, that confirms it was killed by iOS for using too much memory.
The only other way an app could exit without leaving a crash report is if it erroneously called exit().
For more information, see "Debugging Deployed iOS Apps", and "Understanding and Analyzing iOS Application Crash Reports".
Not sure but reading the registers might help.
First go to Exceptions tab and 'Add Exception Breakpoint' using the + at the bottom left corner.
Then when the app crashes click on "0 objc_exception_throw" under Thread 1
Finally in the console enter:
register read
(you should get a list of registers)
po $rax (normally the exception is in 'rax')
(you should see the exception output on the console)
Hope this helps.
That does sound like maybe the device is running low on memory and shutting you down. There's lots of threads on stackoverflow on debugging memory warnings.
This one talks a little about what to look for when using the Instruments tool.
Here is an explanation of how to get the memory warning level, and what the codes mean.
There is no fixed memory limit on iPhones. I've asked Apple support representatives this question, and they wouldn't give me a fixed answer (probably because the algorithm does not actually enforce any one hard limit for a 3rd-party app).
And, yes, ARC can be a wonderful thing. In your situation, you might have to rework a lot of code to make it all ARC-compliant, but ARC is definitely a useful feature, and can produce programs with fewer memory problems, with less work by the coders (leaving you more time to fix other problems!)
I recommend instrument
https://developer.apple.com/library/mac/#documentation/developertools/conceptual/InstrumentsUserGuide/AboutTracing/AboutTracing.html
In my case i closed all other apps and it started working normally, maybe it was a memory issue
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.
I have implemented pdf reader application for ipad.Its working fine in simulator.But its terminated in device with exit status 10.I done know whats happning.Please help me solve this problem.
Thanks in advance.
John,
Most likely it is a memory leak that is causing the app to get killed for consuming too much memory. Run the app with the Leaks tool (in the Run menu of XCode) and check how much memory gets allocated on load or during use.
Try it on the simulator first since you said it won't work on the device. Also, be sure you are releasing all objects you create after using them (but only the ones you create, not the ones Apple does).
A good reference guide to memory management: http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.pdf
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.