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?