Memory leaks destroying my application?


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



I think you're confusing terminology here. A memory <strong>leak</strong> is when you don't release an object after you're done with it.

A leak <strong>won't directly cause a crash</strong>. 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 <em>not</em> 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 <em>over</em> releasing), in which case your instruments leaks tool isn't going to help you.


You can use Instruments to see where potential leaks are.

Here is a good tutorial. <a href="http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/" rel="nofollow">http://mobileorchard.com/find-iphone-memory-leaks-a-leaks-tool-tutorial/</a>


If you need to find out leaks and source of crash. you can try these

<ol><li>try to find as many leaks as possible from Instruments and fix</li> <li>set NSZombieEnabled for your executable parameters and debug application crash</li> <li>change all your autorelease objects to use alloc init as much as possible.</li> </ol>

-- 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.


  • Servlet interface is not a javax.servlet.Servlet
  • Volley and Gson -Sending a POST request using JSONObjectRequest
  • How to use a remote static file server while developing with django manage.py runserver
  • How locks (S,X,IS,IX) work in Mysql with queries like FOR UPDATE/LOCK IN SHARE MODE?
  • Event handler not working in Internet Explorer
  • iOS app terminated due to memory pressure
  • Android EditText change focus after validation and showing the error in a Dialog
  • Uncaught TypeError: ctorParameters.map is not a function
  • NSWindowController circular dependency caused by bindings?
  • How to debug “Terminating in response to backboardd's termination”
  • How can i automate 'Settings' app in real iOS devices?
  • google-maps-sdk-ios - arm 7/iphone 5 issues for Google Maps 1.4.3 for iOS
  • Xcode duplicated devices bug
  • Localization issue Xcode
  • Retrieve Facebook Account Information in ios 6
  • change search magnifying glass to UIActivityIndicatorView
  • Eclipse MTJ doesn't see Java ME SDK 3.0 devices
  • blade.php method outputting it's result to the form
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Debug.DrawLine not showing in the GameView
  • CSS Linear-gradient formatting issue accross different browsers
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Sony Xperia Z Tablet not found by adb
  • TFS: Get latest causes slow project reloading
  • Controls, properties, events and timers running in design time
  • Can I make an Android app that runs a web view in Chrome 39?
  • How to make Safari send if-modified-since header?
  • How to pass list parameters for each object using Spring MVC?
  • SVN: Merging two branches together
  • Hibernate gives error error as “Access to DialectResolutionInfo cannot be null when 'hibernate.
  • php design question - will a Helper help here?
  • How do I rollback to a specific git commit
  • AngularJs get employee from factory
  • How to CLICK on IE download dialog box i.e.(Open, Save, Save As…)
  • Setting background image for body element in xhtml (for different monitors and resolutions)
  • Can Visual Studio XAML designer handle font family names with spaces as a resource?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Authorize attributes not working in MVC 4
  • JaxB to read class hierarchy
  • Python/Django TangoWithDjango Models and Databases