dismissViewControllerAnimated sends message to zombie object

I have two UIViewControllers, VC1 and VC2. VC1 has a button that invokes a triggered Modal segue to VC2. This segue is defined in the storyboard. In VC2, the user can return to VC1 using a pan gesture that executes this line of code:

[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

This code has worked for a long time. However, all of a sudden when this line runs, the app crashes. I enabled zombie objects and I can see this error:

-[VC2 retain]: message sent to deallocated instance 0x7f843a81e200

I've run the zombie profiler and here are the results:

UIClassSwapper initWithCoder seems to be where the app crashes, and there appears to be a an over retained object there, but I can't get any further. When I set an exception breakpoint, I just get into the assembly code, and this isn't of any apparent help.

So, there are a couple of questions here. The first is simply what am I doing wrong in how I am presenting and dismissing this view controller? After that, I don't know how to crack into the event history to figure out how to handle this zombie object.

Any help is appreciated. Thank you!


It seems that you use ARC project. Please provide more code: 1. How you initialize presentingViewController property (and declare). Is it (nonatomic,strong)? 2. How do you put this ViewController to the screen. Is it a kind of modal view controller etc?

-- added after comment. ARC based project decides automatically if the object is needed or not and removes it from the stack automatically. So, the only one useful recipe to avoid this problem is to add NSNotification observer and post there notifications time after time. It will keep view controller in the stack and avoid automatic release. Another solution - check if the controller is still in the stack:

    if (!self.presentingViewController) [[THECONTROLLER alloc] init];

The third one - is to use some object to declare VC1 and VC2 as class variables, and present them as modal view controller when needed. In this case, object and its variables will be kept untouched as long as any of VCs presented.

In any case, the Exception happens because ARC considers that VC is not needed anymore and releases it atomatically.

Need Your Help

New content appear in my website when adding iron router package

meteor iron-router

I just added iron:router package to my meteor project and now at the end of my website it shows this

Class Name in Windows Forms

winforms class-names

I wonder about dynamically changing of class name in .NET application. For example WindowsForms10.SysTreeView32.app.0.19fd5c7. The last string "19fd5c7" would change, but I don't know what makes it