32

I have problem with Thread 1: EXC_BAD_ACCESS (code=1, address=0xf00000c) and I don't know how to resolve it. It appeared when I change some object in core date and save it and I try to pop this controller to parent. This error is in main() with retVal. here is some code

        int retVal;
    @try {
        retVal =  UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
           */\ error is here**
    }
    @catch (NSException *exception) {
        NSLog(@"%@", [exception callStackSymbols]);
        @throw exception;
    }
    return retVal;

After re-runing app all my changes are in core data. What is more this problem is only on iOS 7. iOS 6.1 is ok.

Does someone have idea how to resolve it?

user2375706
  • 705
  • 2
  • 8
  • 14
  • 1
    Can you attach the full stack trace here? It's unlikely that the error is in `main()`, it's more likely somewhere deep in your code. You can also try running your application in Instruments with the "Zombies" trace template, which should help you track down the object that's causing problems. – Craig Otis Oct 04 '13 at 14:20
  • 9
    I *promise* you, the error isn't in `main()` that's just where the debugger is dumping you after everything else unwinds. – ipmcc Oct 04 '13 at 14:20
  • 3
    `EXC_BAD_ACCESS` is a hard crash and cannot be caught via `@catch`. – bbum Oct 04 '13 at 15:32
  • 1
    This will also be a case sometimes when you try to do some UI things on background thread. I was showing an alert from background thread. – Vivek Sinha Jun 23 '17 at 11:48
  • 1
    If your issue is with `CoreData`'s `NSMAnagedContext.save()`method. I recommend **saving the context from within the perform block**, to make sure all data needed by CoreData will be still available – marcelosalloum Apr 18 '19 at 12:48

10 Answers10

23

I just had the exact same problem.

Looked here and found nothing so I started backtracking until I thought, maybe I should try Clean Build Folder

I was glad it was as easy as CLEAN BUILD FOLDER!!!

Product- Clean Build Folder(⇧ ⌘ K)

Superlative
  • 514
  • 1
  • 4
  • 14
  • The only solution for me; in my project the problem was that the EXC_BAD_ACCESS has been raised when I did changes in my cocoapod in development in local environment; I presume that Xcode doesn't get changes but give no errors at build time. So, clean build folder helps. thanks – ricky.tribbia Jul 31 '20 at 07:13
20

As a comment said this error is likely to be deep in your code. If the culprit is a zombie, the easiest way to find it is to run it (preferably in the latest Xcode, currently Xcode 5, as it has been improved) in profiler and choose "Zombies". When it fails, you can see the history of everything that has happened to the object.

Also, set an exception breakpoint. You may get a break when the error happens instead of in main, where the exception gets passed up.

Peter DeWeese
  • 18,141
  • 8
  • 79
  • 101
13

I resolved this problem with "Zombies" and the problem was with [UIScrollView(UIScrollViewInternal) _notifyDidScroll]

I added

- (void)dealloc {

  self.tableView.delegate = nil;

} 

This problem was only in iOS 7.

Thanks for help!

Hafiz Ismail
  • 3,195
  • 1
  • 25
  • 21
user2375706
  • 705
  • 2
  • 8
  • 14
11

I have resolve this issue only by debugging the source code and re-analyze my logic.

Below are some reference that help me lot.

EXC_BAD_ACCESS means that message was sent to a point in the memory where there’s no instance of a class to execute it. Thus “bad access”.

You will get EXC_BAD_ACCESS in 3 cases:

  • An object is not initialized
  • An object is already released
  • Something else that is not very likely to happen

That’s already a good starting point. Start using the debugger, if you recently added a new object to the class you’re working on, put a breakpoint at the line before the freshly added object is used for the first time and check the values in the debugger.

What’s happening most though is that you will be sending a message to an overreleased object – i.e. object that is gone from the call stack. In this cases everything (and indeed everything) you will get in the console will be just :EXC_BAD_ACCESS

This is because the object is gone, there is no information what class was it, or what source file or anything else.

Please try to avoid using zombies for this.

Jano
  • 62,815
  • 21
  • 164
  • 192
KTPatel
  • 1,212
  • 4
  • 19
  • 24
3

EXC_BAD_ACCESS means there is no instance of a class to execute it.

There are 2 or more possibilities:

  1. An object is not initialized
  2. An object is already released

Please debug application carefully and analyze each object carefully. That might solve your issue.

1

I solved the same problem by finding out that the name of one of my NSString variables had the same name as one of the frameworks' class variables. Took seconds to change the name a little and problem disappeared.

With such a huge number of class variables in frameworks, it is very likely that once in a while, every programmer just by coincidence names some variable in his class exactly the same as one used somewhere in framework classes. So it doesn't have to be Xcode bug in most cases.

AstroCB
  • 12,337
  • 20
  • 57
  • 73
Stan
  • 11
  • 1
1

In my case, I was using third-party library and I forgot to set custom-class name in Storyboard Identity Inspector

Nay
  • 677
  • 1
  • 8
  • 14
0

And there may be another issue which I faced today: I had a mutable dictionary with a non-object entry try. There was a code snippet with adding a BOOL value to the dictionary. So no wonder that I got this error =).

AOY
  • 355
  • 3
  • 22
0

In my case it was trying to log an Int32 with %s in print statement

Ivan
  • 1,254
  • 12
  • 25
0

in my view this is the equivalent of every other language NullPointerException,

but unlike other languages there are no hellping pointers (class name / method or line of the occurrence / god forbid a Stacktrace),

so the only thing i could do to solve it fast is to start printing main functions and views, (a very primitive solution),

  1. create a swift: Debug.swift
  2. add this function into Debug.swift:
public func trace(_ message: String = "", file: String = #file, function: String = #function, line: Int = #line)
{
    print("****  \(file).\(function)[\(line)]: \(message)")
}

then you can use it like this:

trace("initializing")

to use it inside a var do this:

let _ = trace("initializing")

this should print something similar to this:

****  /path/to/my/file/MyFile.swift.someFunc()[18]: initializing

this is how i started adding debug lines to gain some flow record, so next time i have a EXC_BAD_ACCESS i will have a clue where the problem leis

don't forget to disable the prints during production deployment

Shaybc
  • 2,628
  • 29
  • 43