0

I have a project with custom back/home button and when user hit it i call:

  -(IBAction)backBtnTapped:(id)sender {
    [appDelegate.navController popToRootViewControllerAnimated:YES];
}

Now i see that it didn't call viewDidUnload method. Why? How to force unload VC (and views in it) in ARC project?

Jakub
  • 13,712
  • 17
  • 82
  • 139

1 Answers1

1

The method viewDidUnload will only be called when you have a memory warning not when the view is out of the screen, for this you probably will want to use viewDidDisappear: or viewWillDisappear

For a better explanation of the viewDidUnload method you can take a look at this question: When is UIViewController viewDidUnload called?

So you probably did not need to care when your viewDidUnload is called, only that it do what it need to do. Also that you are taking care of what you need to take care in viewDidDisappear: or viewWillDisappear.

Force the unload is probably not the best way to take care of that, maybe if you have a lot of logic in this method you need to change it to some other method. Do not worry about call the release or dealloc, just be sure that you do not have circular references in your project, and also that you are using the weak and strong references appropriately so the arc will work well.

Hope it help you!

Community
  • 1
  • 1
ggrana
  • 2,335
  • 2
  • 21
  • 31
  • I'm sure i don't have circular references, I have a pointer to this screen only in one place and it still not dealloc when popToRoot... – Jakub Aug 29 '12 at 14:21
  • 1
    This view controller have some delegate or some other object, maybe some object that he create, has some reference to it? Maybe it is delegate of some view inside it. – ggrana Aug 29 '12 at 14:23
  • This controller use `UIScrollViewDelegate` and few objects (also created by this VC). Inside View's have also delegates: `UIScrollViewDelegate`, `UITableViewDelegate`. – Jakub Aug 29 '12 at 14:42
  • This references needs to be weak, if they are strong they will create a circular reference and will not dealloc your object, maybe you need to remove the delegates, because this can retain you object alive. If I know more about what you are trying to do and about your code I can help more than that. – ggrana Aug 29 '12 at 15:11