Which objects reference my ViewController strongly?

Which objects reference my ViewController weakly?

  • I used to have a retain cycle in one of my ViewControllers, but after a lot of debugging, I found the culprit and fixed it. But now, my app crashes if the VC in question has been present before but rightfully disposed of, and I switch view in my TabBarController. I enabled NSZombie and checked the message that was sent that causes the SIGABRT. -[OrderViewController respondsToSelector:]: message sent to deallocated instance 0x151fdc00 In the stack trace I only find system library calls, none app specific. What are possible causes that the framework will still make a call to my VC? Is there a way in Xcode to see which objects have a weak reference to this specific instance of the VC?

  • Answer:

    I have found a way to debug this. Find culprit Place Exception breakpoint Reproduce crash In the stack trace, click on the first non __forwarding__ issue Look for the cuplrit, by typing in the console in Xcode: (lldb) register read General Purpose Registers ebx = 0x790257a0 edi = 0x01119988 "tabBarController: shouldSelectViewController:" esi = 0x08a1fad1 "delegate" ebp = 0xbfff8778 esp = 0xbfff8740 eip = 0x0099415c UIKit`-[UITabBarController _tabBarItemClicked:] + 102 10 registers were unavailable. edi = message that is sent, esi = object you send the message to, eip = why the message is sent. This gives you information where the nil message is sent. Solution I found the issue later because of this. I nullified a delegate in ViewDidDisappear, but should have done so in ViewWillDisappear, since the pointer I was using was not valid anymore in ViewDidDisappear. This code does not work. In this case, self.tabBarController is already nil, so I cannot use this reference to nullify the delegate. - (void)viewDidDisappear:(BOOL)animated { [super viewWillDisappear:animated]; self.tabBarController.delegate = nil; } This code does work. I added a NSParameterAssert to check that the reference is valid before using it. - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; NSParameterAssert(self.tabBarController); self.tabBarController.delegate = nil; }

physicalattraction at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

If your view controller is a delegate for any other object, set that delegate property to nil inside the view controller's dealloc.

rounak

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.