den330
den330

Reputation: 403

When should "self" reference be weak in IOS?

I just learnt that if you don't make it weak, your viewControllers won't be deallocated(Strong reference). Does that mean every time you close your app, you still leave some "Garbage"(viewControllers) in memory if your did not make it weak? If that is the case, is it true that "weak" should be mandatory for "Self"?

Upvotes: 1

Views: 106

Answers (1)

Laurence Wingo
Laurence Wingo

Reputation: 3952

It depends on what self is referring to in your architecture. If self is referring to a type that needs to be retained in your application then yes it will remain when the app goes to the foreground. You may want to be sure this is necessary and also make sure you avoid strong retain cycles.

Upvotes: 1

Related Questions