Memory leaks destroying my application? - iphone

I'm in big trouble now, my iPhone application keep terminating again and again due to memory leaks and I am unable to judge that where are those leaks. Tell me what step can I take in order to resolve this problem.
Thanks

You can use Instruments to see where potential leaks are.
Here is a good tutorial. http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/

I think you're confusing terminology here. A memory leak is when you don't release an object after you're done with it.
A leak won't directly cause a crash. Leaks can indirectly cause crashes if you run out of memory as a result of not releasing lots of objects. However, if your crashes are happening in the simulator as well this is almost certainly not the case (the simulator having far more available memory than the device). As Daniel says, you can use the instruments tool to find out what's leaking.
Another good method is to use the XCode static analyzer - you can have it analyze your code and detect most common leaks.
Now, if your app is crashing and it's not because of a memory leak (you'll be able to tell this because you'll have memory warnings outputting to the console) then chances are your problem isn't a leak. Perhaps it's a bad access (you're over releasing), in which case your instruments leaks tool isn't going to help you.

If you need to find out leaks and source of crash. you can try these
try to find as many leaks as possible from Instruments and fix
set NSZombieEnabled for your executable parameters and debug application crash
change all your autorelease objects to use alloc init as much as possible.
--
worst resort is if it keeps crashing even after trying all the above three. you write memory intensive module of your code in a thread and clean up that thread. I've noticed usually when threading is done the memory footprints are much cleaner. This is just my opinion, but the above 3 you should do.

You could also Build + Analyze your application in XCode itself (Cmd+Shft+A or Product > Analyze). It'll show you the more obvious leaks.

Related

Is one memory leak normal for an app?

I tested my app with the Leaks tool to determine leaks. I resolved all leaks but one.
This one seems difficult to remove. I am working on it but not sure what will remove the leak.
Is it normal for apps to have one or two leaks which don't leak that much memory over the usage of the app?
A memory leak is a bug much like any other bug. They are very easy to measure, though, and in some situations they can cause fatal crashes, so a lot of effort is put into dealing with memory leaks.
But most apps, memory leaks or not, have bugs in them. And a bug isn't automatically a blocker just because the bug causes leaking of memory.

Analyzer Results vs Leaks by Instruments : iPhone memory leaks

I fixed memory leaks of my application using
X-Code->run with performance tool -> leaks
I submitted my application and later I analyzed my code attaching to device like Build & Analyze for device i got many Potential Leaks popped up when i pressed Product then cmnd+shft+B.
What is the difference between the two, was my fixing of leaks based on instruments wrong?
Is it like some leaks pointed by analyzer may actually cause leaks which are not shown/caught by Performance tool?
When you run the leaks performance tool it will let you know WHEN a leak actually happened. Build & Analyze warns you of potential leaks that COULD happen while your program is running.
Your fixing leaks based on instruments was not wrong, but you should also carefully look into the leaks build & analyze tells you, as they could potentially leak when the program is actually running.

iPhone/Objective-C - Memory leaks in QuartzCore library

I am running the Instruments Tool (Leaks) and am receiving memory leaks in the QuartzCore library and don't know exactly where in my code this is occurring. Usually I'm able to pin point the line where the leak is occurring, however the instrument tool isn't giving me anywhere to view this type of information.
What would be some other things I could look at in terms of diagnosing such a leak?
First, try running this on the device. Sometimes the simulator will report leaks that do not exist on the device.
Secondly, open up the stack trace (right sidebar) and see what code of yours might be involved higher up in triggering this call, then you can think from there why that code might be leaking.
One additional bit of advice. Instead of playing with leaks there, switch over to ObjectAlloc and use the Heapshot feature - if you know about where the leak is, use the heapshot to set a base memory measurement and every time you hit the "heapshot" button after that you'll see a kind of memory "diff" against that baseline you set. Solving any over-retained problems might also fix your leak.
If you’re only leaking 16 bytes at a time, it’s really not likely to become an issue in your app. And if the leak is occurring in a system framework, it probably isn’t your fault.

is it possible to create a 100% leak free ipad application

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 :(

Leaks on app exit

I am wondering is there a way to find out memory allocations that dont get deallocated on iphone application exit or it's termination .
I have been using instruments fixed most of leaks that I had in my application, but i am worried that there are still some allocation that i didnt release.
Thanks
In short, don't bother trying to find and fix leaks caused during application termination. It is quite likely -- almost guaranteed -- that neither Cocoa nor the iPhone frameworks try to release all memory on termination as doing so is entirely a waste of CPU cycles.
If you are going to hunt down leaks, do so through using your application as your users do, keeping an eye on the Object Alloc instrument's analysis.
What can be useful, though, is putting a hook in that is triggered before termination is an absolute. Stop there and make sure the app's object graph is as expected.
No need to worry about cleaning up memory on application exit. The operating system will wipe out any memory allocated to your application at that point.
but if you use opengl please clear out your buffers :P.