views:

38

answers:

2

The setting is the following:

  • I have a cocoa object in a nib file that is loaded when the NSWindow and view is loaded
  • The window can be closed
  • I also access the object programmatically

Now what happens in some situations is that I get a crash, when I try to send a message to the object, but it has been deallocated before (because the window is closed). The crash looks like this:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV) 
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000017 
Crashed Thread:  0  
Dispatch queue: com.apple.main-thread

Application Specific Information: 
objc_msgSend() selector name: ...

Is there any way to check if the object is available or not? Checking for nil does not work, it is not nil. Probably the control flow is not perfect, and I could rewrite other chunks of the app to make this problem go away, but I think this is a more general problem that I have no solution for, and it boils down to this:

How can I make sure that an object that is loaded from a nib is set to nil on deallocation?

A: 
Tobi
Hm, I tried this, but somehow it got released anyways (or so it seems). Still, this also seemed the right way to me, so perhaps I just messed it up someplace else (pretty complex app).Thanks also for the explanation about the variable/object distinction - should have thought of this myself, but now it's very clear to me. Thanks!
darklight
It might be helpful to printout the the retaincount with [myInstance retainCount]. If that doesnt help you could overwrite the retain and release-methods (inherited from NSObject) for your given class by calling super and then printing out the retaincount. Although i dont know for sure, i'd guess there's a way to do sth similar with the debugging tools of xcode.
Tobi
Thanks for getting back to me, that helped a lot. I think I finally removed that bug now :)
darklight
A: 

Try deactivating the window setting "Release when close" on Interface Builder.

IlDan
Hm, thanks for the hint, but it isn't even enabled - seems to be released anyways.
darklight