I am not sure if something has changed in the iPhone SDK 3.0 but I am getting the strangest error. I have a view controller hierarchy where I switch between view controllers
Lots of confusion here... let's see if this helps:
What I can't understand is why the system is trying to message this controller even though it has been deallocated and is there a way to tell the system that the controller doesn't exist any longer.
While deallocation destroys the instance of an object, it doesn't destroy the references to the instances. With Zombie detection enabled, deallocation causes the runtime to substitute a zombie for the instance. The zombie then detects and logs when it is messaged.
The reason why this happens is because the object has been deallocated without also removing all references to the object from the application's object graph. In this case, it looks like the deallocated controller was never unset as the controller from the UIWindow instance.
That is, the processing of the notification is a red herring. In that backtrace, the notification has already been delivered and UIWindow is in the midst of processing it. Thus, the problem is somewhere between the UIWindow and your application. Most likely, your object has been deallocated before being removed from the window as its controller or delegate.
Before your program is truly done with an object -- before you send the last -release
call that balances the last existing -retain
your application caused or called -- you must make sure that all weak references to the object are destroyed. For example, if your object is the delegate of a UIWindow, make sure you set the delegate of the window to nil
(or some other object) before sending that last -release
.
Now, in this case, it may also simply be that you have over-released the object. You might still need the object around, but an extra -release
or -autorelease
somewhere is causing it to be destroyed before you were done with it.
I had been experiencing the same problem until deleted some 'bumping' code lines I used to push animation like those:
UIView* superv = navigationController.view.superview;
[navigationController.view removeFromSuperview];
[superv addSubview:navigationController.view];
Definitely, the above is 'breaking' way to go since 3.0 SDK had been issued by Apple. I've been forced to use push/pop approach instead. Didn't have the problem with 2.x as well. Make sure you don't have something similar in your code.
Hope, it helps.
I also had the same problem but wasn't able to leave a controller hanging around as Mark Smith's suggestion. Removing the view controller with autorelease rather than release or a retained property seemed to do the trick.
Seems that the parent UIWindow/framework needs the view controller to hang around a little while longer to allow it to remove the delegate link.