Search code examples
iosobjective-cmemory-managementios7iboutlet

IBOutlets Strong or Weak - Does it Actually Make a Difference to Memory Management? (ARC)


I've been reading a lot recently on here and other sites about whether IBOutlets should be strong or weak. The official verdict is that they should be weak, except for when they reference top level xib objects.

This is fine.

However what I don't yet have a clear understanding of is why setting them to strong or weak actually would make a difference in terms of the app's memory management. In particular it seems since iOS6, viewDidUnload is not called on receiving a memory warning anymore, so in this sense the choice of weak or strong for IBOutlets would make no difference.

Am I right in thinking though that for view controllers no longer on the navigation stack (i.e after they have been loaded then popped), that any IBOutlets declared as weak would then be released ?

Thanks for any insights !


Solution

  • IBOutlets can declared weak because they will be created during XIB parsing and added to the UIView stack...so you don't need a strong reference to the object.

    When you declare an IBOutlet weak you ensure that when the main UIView of UIViewcontroller disappear every subview will be deleted without any memory leak.