Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

objc_retain EXC_BAD_ACCESS

I have been having a bit of a bug while testing on iOS 6 with my current iOS 5 app.

We have experienced a lock up on a method return for an innocuous method that internally used blocks, but not as properties. The issue is that calling the method works, so does every line of code within the method (including the block utilizing code)

I tried using [block copy] before calling the block, but there was absolutely no change.

like image 696
The Lazy Coder Avatar asked Sep 14 '12 04:09

The Lazy Coder


People also ask

What does thread 1 Exc_bad_access mean?

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.

What is Exc_bad_access Kern_invalid_address?

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000. This indicates that your app crash because it tried to referenced NULL. Code Block. 0 CoreFoundation …

How to find EXC_ BAD_ access?

To debug an EXC_BAD_ACCESS, you can generally find out the where the dangling pointer is by enabling zombie objects. Choose edit scheme, then Diagnostics tab in the Run section, then click the 'Zombie Objects' option. Another cause for EXC_BAD_ACCESS can be infinite recursion, which can be found by adding some logging.


1 Answers

turns out the function definition of my code was declared in an internal interface and did not have a return type.

Here are some graphics to illustrate this issue.

The Initial Error

The Initial Error

The Stack Track

The Stack Trace

The Method in Question (isolated from self to determine the issue exact location)

The Method in Question

The Function Implementation (this is what is called, and returned)

The Implementation Line

The Definition in the Private Interface

The Definition in the Private Interface

I decided to look at the function call, and noticed it returning (id) rather than void

Function returning (id)

And Finally the only code change that alleviated this bug.

Code Change

Explanation

This bug reared its ugly head when my client called me saying our app does not run on ios 6

I was forced to download iOS 6 and Xcode 4.5 for testing this out.

I did indeed crash every time the app was run.

After hunting down this bug on stack overflow among other sites linked to by Google, I tried the block issue that some others are experiencing. And did a copy wherever I could to try to alleviate the issue of retained object falling off the stack.

I was not using block properties so I just called copy on the blocks themselves.

This did not help.

Finally with another developer going over it with me. I was stepping back and looking at it from another angle, and decided to try to determine what the heck was being retained.

It turned out the result of the function was being retained. And the only way I figured that out was to look at the value that auto complete showed me as the return type.

I knew the return type to be void, however it was telling me that the return type was id and that is what sparked the investigation into the method definition.

I hope this helps others that have this issue as I spent about 2 hours hunting it down and it turned out to be a semantic issue between a result type that should never have existed.

like image 111
The Lazy Coder Avatar answered Sep 27 '22 21:09

The Lazy Coder