-2

I am trying to avoid retain cycles within my code and I had this question that i was not sure about. Any insights would be appreciated.

If a UIViewController is successfully de-allocated, does this also mean that all class objects within the viewController have also been successfully released from memory?

I used the following function to determine whether a UIViewController has been de-allocated

deinit{}
user3013144
  • 61
  • 2
  • 13

3 Answers3

1

If your ViewController has strong reference from any class object then your ViewController can`t be de-allocated.

According to Apple document:

An instance is no longer needed, ARC frees up the memory used by that instance so that the memory can be used for other purposes instead. This ensures that class instances do not take up space in memory when they are no longer needed.

zeytin
  • 5,545
  • 4
  • 14
  • 38
1

If a UIViewController is successfully de-allocated, does this also mean that all class objects within the viewController have also been successfully released from memory?

No. That might happen, but class objects are reference types. If there is any other reference to any of the class objects within the viewController, that object will live on. Indeed, it is crucial that that should happen. It would be a total disaster if, say, another view controller was referring to this object and the object went suddenly out of existence just because this view controller was deallocated.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

If a strong reference to one of the UIViewcontroller's class objects exists from outside the UIViewController, then that class object will not be released from memory.

trout
  • 86
  • 2