I am using Xcode's Instruments for first time and my app is based on ARC and built for iOS 6.1, but currently re-modified for iOS 7 and works well without crashing. I have run tests on a physical iPhone device also and have seen no problems at all.
Running Instruments keeps giving me the following details, but I have not seen any of my classes or objects apart from Libraries.
Is ARC not taking care of this? Do I need to manually release objects for all memory allocations?
Can someone please help me with what is going on here?
Any help would be much appreciated.
This post may help you: Does ARC work with Core Graphics objects?
Also, you need to be aware of retain loops. one object holds a reference (strong) to another object which also holds a reference to the first object (strong). This is most common in using delegation.
Related
I am implementing an iPhone application and when I ran this app initially it was showing memory size was 5.3MB
and after 10 min it was showing memory size was 185.3 MB.
I'm releasing objects manually and also analyzed my app, I have only one memory leak(that to return object in class method). What was the problem? is it harm to app while apple approve it?. Please help me. Thanks in advance.
No, you really shouldn't release it with this kind of a leak (or memory accretion). It will lead to crashes and that will cause data loss and upset users.
Heapshot analysis is designed to track down these kinds of problems. That is, use the Allocations Instrument to track memory growth over time iteratively and then eliminate the large memory consumers.
Apple will probably approve it as long as it is not crashing within the review time.
But no you should not release the app if you have a memory leak like this. Your app will have poor user experience and might crash if the users device memory runs full. You will get a low app store rating.
I would suggest you find out which object is taking up so much memory and fix it. If at all possible switch to ARC, this will take away some leaks.
I have same problem too. NSZombieEnabled flag work for me. I think this might be helpful to cope up with ARC. I have followed this link: How do I set up NSZombieEnabled in Xcode 4?
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 developing an iPad app and found some memory leaks using Instruments and Analyzer. I tried to release some objects which resulted in the crashing of my app.. Are memory leaks allowed in an app? If so, until what extent they are allowed? Is there a way to completely remove the memory leaks with out the app getting crashed??
Generally speaking, it is possible to make sure that the code which you write is leak free. This is not to say that Apple frameworks and internal libraries won't leak at all.
If you call alloc, new or copy make sure to call a corresponding release or autorelease. Apps that leak a lot are bound to crash often. Apps that crash often are likely to be rejected from the App Store.
Please read this. We can create an application with 100% leak free. Enable NSZombieEnabled to check why the crash occurs.
It's best to remove as many leaks as you can.
But if there are a few remaining in your application that you can't remove, Apple will still accept your application - as long it doesn't crash frequently.
Just make sure when you alloc something - it's released with release or autorelease.
That's the best way of making sure leaks don't occur.
Leaks are much, much easier to not have in the first place than to try plugging later when the app has memory issues. Fortunately in the iOS/Cocoa world the memory management rules are clear and simple. However as others have said there could be leaks in code you didn't write :(
I'm checking memory leaks in my apps using Instruments Leaks tool.
After fixing all leaks whose responsible library is my app. I figure out that there still have a lot of leaks whose responsible libraries are iOS's framworks, based on what Instruments said?
This is a screenshot of Intruments:
I think these leaks may be caused by some of my misuse of frameworks' methods.
What is your approach when getting leaks like these?
Thanks!
Well Apple Developers are also human, and they also can make mistakes. Alternative would be to create your own framework exactly same to that of Apple's but that will not be nice thing to do as Apple will certainly come up with upgrades and fixes in future that will resolve the issues.
The only solution would be to report bugs to Apple about memory leaks, even I have seen that framework has lots of memory leaks.
There are also other reasons for memory leaks, instruments may show memory leaks in apple's framework, but it is not necessary that it is caused by the framework's bad code, indeed it could be the bug in our code where we did not follow correct steps, for example we add observers but we do not remove them, we bind for events but we do not remove them, so if we have not done cleaning operations correctly, instruments may show leak but somewhere else.
I've been noticing the same with one of my apps and in the end, after trying to figure out what I am doing wrong, I came to the conclusion I'm doing nothing wrong and that Apple's frameworks have memory leaks as well.
So I don't think there's anything you can do.
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.