loup4
loup4

Reputation: 151

Bad Access on delegate only on iPhone 4S

My application crashes after random times when delegate is called (inside IBAction method) but only on iPhone 4S in Simulator. Every other newer iPhone works great.

@propert (assign, nonatomic) id <MyDelegate> delegate;

Of course I am using ARC. What can be the reason?

SOLVED: Argument passing in delegate method in some conditions was unintentionally released from memory. Changing it to strong type helped.

Upvotes: 0

Views: 43

Answers (1)

matt
matt

Reputation: 535304

The reason is that you are using assign. This basically means "crash me". If your delegate goes out of existence, you are left pointing to garbage, and any attempt to access that garbage will result in a crash. In effect, you have thrown away the advantage that ARC gives you.

To restore that advantage, use weak instead. Now if your delegate goes out of existence, you will have nil and can proceed in good order.

Having gotten rid of the crash, you can now check for nil and try to figure out why your delegate has gone out of existence when you evidently don't expect it to. Keep in mind that the problem you are seeing is what we call "diagnostic"; the delegate may have gone out of existence long ago, or it may never have been assigned in the first place, but figuring that out is a completely separate matter.

Upvotes: 2

Related Questions