swiftretain-cycle

If a UIViewController is successfully de-allocated, no retain cycles?


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{}

Solution

  • 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.