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.
Related
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.
I have run my app with instrument and i m getting a memory leak but i dont know at which point that memory leak is happening.
How will i know at which point memory is leaking.
Check out this article "Actually finding a memory management error with Instruments", from the big nerd ranch. Creating "heapshots" is a good way to start narrowing down the code parts that show no obvious memory management errors at first glance. But as ACB stated already, if a system library is leaking (rare case) there's not much you can do about it. But most of the time the memory issue is always in your apps' code somewhere! :-)
It says responsible library is quartzcore, and it is only 16 bytes. As long as it is not in the app and the OS is causing the same, you cant do much about this. I would recommend you to ignore this.
If you are facing issues, check the allocation tool -> Live bytes section and check if memory is shooting up when you are selecting a lot of images at the same time.
I can see from your screenshot that your app is already running in your device/simulator and you are trying to run it again with instrument, try to close your app completely from device and then start it again with instrument.
You can read more details about Xcode instrument from Apple.developer InstrumentsUserGuide
Also I have found another good tutorial about this in Raywenderlich blog
Another good documents is here
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?
hay all..
i hope every thing is good
im a new iphone developer and i did an application and when i finished i test it through allocation test in instrument and shocked from the results..it stole
very very big memory and i don't know what i must do..in the same time i release every variable i was used BUT the real problem was that the application load man images and contains custom cells and custom tables with custom navigation
please help me
It sounds like you're not releasing your objects after you're finished with them, or you're loading an unrealistic amount of images / data into a handheld device. It's pretty hard to help in this instance if we can't see your code.
I found the Stanford iTunes U course really helpful, and they go through the logistics of memory management really well. It's something you really need a good understanding of before/as your write your apps.
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.