views:

30

answers:

2

Hi All,

Can any one guide me with invalid objects created in objective C. I am working on iPhone SDK. I see invalid objects created in the application which crashes the application.

Here is a screen shot of how it looks like

alt text

where as in the log I get Program received signal: “EXC_BAD_ACCESS”.

I require help with the follows.

  • How are they created.
  • How to prevent them.
  • How to detect them.

Thanks in advance.

+2  A: 

That error means you sent a message to an object that had already been released (in other words, the retain count of some object reached zero, so you're over-releasing that object somewhere). In Xcode, you can set NSZombieEnabled to YES in your Debug environment; that will make objects that should be released stick around, and then when a zero-count object is messaged, the debugger should break, you'll get a log entry showing what object was over-released as well as your usual call stack and such.

Make sure to only use NSZombie when you're trying to find an over-released object.

Brock Batsell
The problem occurs when objects stored in the array get invalidated, as show in the image , I am using a app delegate shared array.
Ameya
How to deal with allocated instance which require re initialization like if(notes == nil) notes = [[NSMutableArray alloc] init]; else { [notes retain]; notes = [[NSMutableArray alloc] init];}
Ameya
`else { [notes release], notes = nil; notes = [[NSMutableArray alloc] init]; }`
Alex Reynolds
thanks for the code
Ameya
A: 

I can't see your screen shot, but EXC_BAD_ACCESS is given to you when you are access an object that is usually released before you use it. You can't really prevent coding that, it happens to all of us at some point or another. You're just gonna have to learn how to find your code that is access the object and learn to fix it.

Turn on NSZombies your gonna have to debug your application. Google how to use NSZombies and that should help you find your problem.

Conceited Code