Questions tagged [exc-bad-access]

EXC_BAD_ACCESS is a fatal error related to memory management on macOS and iOS.

This is a kind of crash that occurs when a program tries to access memory (including, but by no means limited to, Objective-C objects) that it has deallocated or had never allocated in the first place.

The correct name is EXC_BAD_ACCESS, not EXEC; the “EXC” stands for “exception”, specifically a Mach kernel exception (meaning that the kernel did not like what your process did; this is not the same as a kernel panic). This isn't a C++ or Objective-C exception, so there's no catching it.

EXC_BAD_ACCESS means that you've freed or released an object and then tried to use it later, or failed to retain an object that you planned to use again later.

To prevent this error from happening:

  • Practice good memory management
  • Run the static analyzer in Xcode to find bugs
  • Run Instruments with the Zombies template to find premature-object-death bugs
2059 questions
13
votes
2 answers

"EXC_BAD_ACCESS" vs "Segmentation fault". Are both same practically?

In my first few dummy apps(for practice while learning) I have come across a lot of EXC_BAD_ACCESS, that somehow taught me Bad-Access is : You are touching/Accessing a object that you shouldn't because either it is not allocated yet or deallocated…
user3721704
12
votes
2 answers

EXC_BAD_ACCESS when trying to create a new NSDictionary

I'm having troubles with creating NSDictionaries in a loop and adding it to an NSMutableArray. Basically I just want to change the names of the keys, but since I couldn't find a function for that I went for following code: - (NSMutableArray…
Lucas G
  • 148
  • 1
  • 7
12
votes
2 answers

EXC_BAD_ACCESS when accessing value in block

I have a pretty complicated table view setup and I resolved to use a block structure for creating and selecting the cells to simplify the future development and changes. The structure I'm using looks like this: var dataSource: [( cells:[…
Moriya
  • 7,750
  • 3
  • 35
  • 53
12
votes
4 answers

CGImage/UIImage lazily loading on UI thread causes stutter

My program displays a horizontal scrolling surface tiled with UIImageViews from left to right. Code runs on the UI thread to ensure that newly-visible UIImageViews have a freshly loaded UIImage assigned to them. The loading happens on a background…
JBx
  • 123
  • 1
  • 2
  • 7
11
votes
1 answer

EXC_BAD_ACCESS (SIGSEGV)

I got this crash report from a remote user, but I cannot find any useful tip to resolve this issue, may be it's a retain problem but I cannot understand why because of I'm using ARC. Very small number of users are issuing this problem. I've tried…
Progeny
  • 672
  • 1
  • 11
  • 25
11
votes
2 answers

How can I avoid EXC_BAD_ACCESS when checking if directories exist?

I'm building an app which caches images in the Documents directory of the app bundle. In order to make sure the directories exist, I want to check to see if they exist and, if they don't, create them at the point at which the application…
abitgone
  • 561
  • 9
  • 29
11
votes
3 answers

How to properly deal with a deallocated delegate of a queued nsoperation

In my current project, several view controllers (like vc) spawn NSOperation objects (like operation) that are executed on a static NSOperationQueue. While the operation is waiting or running, it will report back to the view controller via delegation…
epologee
  • 11,229
  • 11
  • 68
  • 104
11
votes
4 answers

EXC_BAD_ACCESS (code=2) when using NSNumberFormatter

I'm having a problem, which I can't figure out for the life of me. I've searched the internet, trying to understand Swifts's EXC_BAD_ACCESS, but nothing seemed to help. The following code is quite long, but most of the time the comments are all the…
Marcus Rossel
  • 3,196
  • 1
  • 26
  • 41
11
votes
1 answer

Enable and Debug Zombie objects in iOS using Xcode 5.1.1

I have an iOS(7.1) app which crashes due to EXC_BAD_ACCESS. If I am not wrong, this happens due to the use of an object which is already de-allocated. After a bit of searching, I found out that enabling Zombie objects help to pin point the line of…
Sibir
  • 313
  • 2
  • 6
  • 20
11
votes
2 answers

Swift set delegate to self gives EXC_BAD_ACCESS

I'm going through and learning Swift by porting an existing application. I'm stuck on setting a delegate and cannot work out what the issue is. I have a class which extends UITableViewCell import UIKit protocol SwitchCellDelegate{ func…
Moth
  • 765
  • 2
  • 7
  • 14
10
votes
1 answer

EXC_BAD_ACCESS on NSManagedObjectContext save method inside NSOperation and ARC, why?

I have found some problems when saving NSManagedObjectContext inside NSOperation with turned on ARC. Without ARC everything was fine before. It is always gives EXC_BAD_ACCESS during saving. The code looks like this: //on the main…
10
votes
3 answers

Adding a delegate to a custom UITableViewCell (bad access error)

I'm trying to add a custom delegate to a custom UITableViewCell of mine. On this cell I have a button which need to fire a method in the ViewController where the UITableView is located on. I'm doing all the usual steps to add a custom delegate but…
Totumus Maximus
  • 7,543
  • 6
  • 45
  • 69
10
votes
3 answers

EXC_BAD_ACCESS message sent to deallocated instance, but I'm using ARC?

I've got an app that gets information from a SOAP web service and I want to display the results in a UITableView. I had a previous version of this app and I'm creating a new version to basically clean things up and get rid of a bunch of legacy code…
mbm29414
  • 11,558
  • 6
  • 56
  • 87
10
votes
4 answers

iOS5 crashes during runMode:beforeDate:

I have a problem with compatibility of my application with an iOS5 b7 and GM versions. The issue occurs in the next lines of code: do { [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; } while…
Nekto
  • 17,837
  • 1
  • 55
  • 65
10
votes
4 answers

Core Data: solve a strange EXC_BAD_ACCESS error

I am facing a really strange problem with Core Data. Let's describe it: Definitions Let's say I have two models, ModelA and ModelB. In the data model ModelA has a reference to ModelB as a one-to-many association, and consequently ModelB has a…
marzapower
  • 5,531
  • 7
  • 38
  • 76