Copyright (c) 2011 Doron Katz. All rights reserved. DoronKatz registered under ABN 68 954 062 611. Apple, the Apple logo, iPod, iPod touch, and iTunes are trademarks of Apple Inc., registered in the U.S. and other countries. iPhone is a trademark of Apple Inc. App Store is a service mark of Apple Inc. Theme by Cory Watilo

Objective-C: EXC_BAD_ACCESS

Just a quick XCode/Objective-C pointer, for those of you who happen to come across the familiar console error EXC_BAD_ACCESS.  I will be working on an overview tutorial regarding Memory Management, but for now, this quick set of notes would help you generally understand memory issues you may come across and feel stumped!

The  EXC_BAD_ACCESS  that you may get, usually arises from over-releasing an object, and so when you are debugging you may not have noticed that as it crashes deep in the framework stack, when none of your code is visible. 
To combat such problems you must follow the Cocoa Memory Management Guidelines and Apple have some good documentation on that (in fact better than most third-party literature I come across). 
Things to Remember
  • You are only responsible for releasing an object from memory when:
    • you directly have allocated (ALLOC), copy or retain that object, you may proceed with release ing or autorelease ing it. Otherwise, it's not your duty to release.
  • If you need to store a returned object in an instance object you have (i.e self.varName),  you must Retain or Copy it before releasing it. ( I will discuss this more in a future blog post).
  • If you instantiate an object using a convenience method i.e :
 NSString *userPart= [[emailAddress.text componentsSeparatedByString:@"@"] objectAtIndex:0];