EXC_BAD_ACCESS in main.m after converting to ARC - cocoa-touch

I have a simple UITableView application that I just converted to ARC. The conversion supposedly went fine, and the app launches now, but if I navigate into a DetailView, then try to jump back to the RootView, I get a BAD_EXC_ACCESS error in main.m, and a crash. I tried turning on Zombie objects, and that stops the crash, but I also don't get anything in the console telling me what was happening. I turned off ARC, and again, no crash, but also no more info on what was causing it in the first place.
Any ideas on how to debug this would be greatly appreciated.

BAD_EXC_ACCESS are a little tricky, mainly because they don't show up at the offending line which causes the error. Using lldb, you can use thread backtrace to get an idea of what is causing it. This answer contains a great answer with a few ideas on how to troubleshoot similar problems.

Related

Resolving deadlock in iOS app

So I'm trying to convert a project to ARC. The first attempt, I just converted everything and I had this problem on one of my views, it just hangs. I cannot click on any UI element, and nothing is printed to the console, and it doesn't crash. It just sits there.
So in order to start troubleshooting it, I converted all the simple classes and viewControllers, and then for some of the more complex model classes and UIViewController classes, I set the compiler flag for -fno-objc-arc. My app runs better, but it still just gets in this state where it hangs. I've never seen this on it prior to converting to ARC. I was wondering if anyone else has had this problem and what I can do to troubleshoot it. Thanks~
I would press "pause" in the debugger and look at the call stacks for all threads in your app. This can point out why your app is locked up.

iOS Memory Managed differently when Debugging

I am experiencing some odd behaviour - I have a property "key" being released in an object's dealloc, this works fine when I am debugging the app on my iPad.
But, when I launch the app "normally" i.e. without running it via XCode, it crashes immediately and from looking at the crash log, I can see it's because the "key" property is throwing an BAD ACCESS error where it is being released.
Does anyone know why my app might behave differently in these two scenarios?
I can obviously fix the bug, but I am not sure even why it is happening...

"Multiple locks on web thread" error thrown inconsistently

I'm getting a strange error in my iOS app. The error message is as follows:
bool _WebTryThreadLock(bool), 0x22c820: Multiple locks on web thread not allowed! Please file a bug. Crashing now...
The odd thing is that it happens inconsistently -- sometimes clicking a certain button or textField will cause the crash, and other times the same steps won't cause a crash. I originally had a few UIWebViews in one viewController, but I've commented out everything related to them, so as far as I know, I'm not accessing the web thread at all. Even when I did have these UIWebViews in my project, the error often occurred in viewControllers unrelated to the webView. I also got the error once when my app was open on the device and I received an email. The push notification from the email seemed related. Any ideas what might be causing this?
I am suspicious that this might be related to the way we are currently segueing between viewControllers. We are using modal segues and manually dismissing one viewController upon loading another. Is that a bad idea?
Any input would be greatly appreciated.

unrecognized selector sent to instance on deviceOrientationDidChange

Right now my app should only supports Portrait. On Summary/Supported Device Orientations I have only selected Portrait so I'm hoping that my app will not rotate. I was testing the app on a device and suddenly I'm getting the following error randomly:
[UIButtonContent deviceOrientationDidChange:]: unrecognized selector sent to instance
It happens when I rotate the device SOMETIMES, is not consistent, and is not always over UIBUttonContent. I supposed that if I only select Portrait, deviceOrientationDidChange should not be called or should be ignored.
Other times my app crashes with an EXC_BAD_ACCESS (code=1, address=something) but it happens when I rotate the device so I'm guessing that both errors are related.
I don't know what to do with this, it's hard to debug because I don't have feedback, the All Exceptions Breakpoint is not being called, so I don't know where and exactly why this is happening. Any idea on how to debug this is welcome.
These are the classic signs of a memory management error. You have over-released some object and it has been deallocated while something else still references it. Later, something messages it. In some cases a new object has taken its place, but that object doesn't understand the messages it's receiving. In other cases, there's no valid object and you get a crash.
Edited to second the advice to use the Zombies instrument to find the over-release.
Do you have a class that should be called with deviceOrientationDidChange:? When this happens, it usually means that you have a dangling reference to a deallocated object. You should try profiling your app with Instruments in "Zombies" mode.
I solved this issue a long time ago, but I think is good to share what actually helped me on this case.
After trying everything with no results with Instruments I started debugging old-school. I had an idea of "where" the error was so I just commented all the code on that section. I was right, the bug just disappeared along with some functionalities. After that I made "binary uncommenting" (uncomment one half) till I got the bug line. It was a third party library, I had an object that was not being released properly.

NSZombieEnabled isn't helping my obj_msgSend

I'm getting an EXC_BAD_ACCESS with my iPhone app on 0x01ad809b <+0015> mov 0x8(%edx),%edi
I have NSZombieEnabled set to YES but I'm not seeing any class printed out in the debugger like I normally do.
Is there another way to debug this problem?
You have a crash caused, most likely, by corruption of memory, using a variable that isn't initialized, and/or casting a non-object type to an object.
First, post the backtrace of the crash. That will provide more context.
Second, try Build and Analyze. Fix any of the problems that it identifies.
Finally, if this is a new crash, go back to a revision right before the crash and then roll forward until you hit the crash. What are the changes made over that span of time?
With more context -- the crash log, in particular (or backtrace, at the least) -- more specific debugging techniques can be offered.
You can select Breakpoint navigator and add breakpoint on all exceptions. Maybe it will help.
Try with malloc info as well.
Use Instruments to Profile and detect zombies instead.
Change the build target to the Simulator
In the Build menu, select Profile
Instruments will open, then select the Zombies instrument
This automatically sets up the NSZombieEnabled flag and will popup a message whenever a dealloced object is messaged. Clicking the disclosure will show the memory management events of the object.