Are viewDidUnload and dealloc always called when tearing down a UIViewController?

后端 未结 2 1849
深忆病人
深忆病人 2020-12-05 14:18

I\'d like to know whether or not both viewDidUnload and dealloc are always called in succession in the UIViewController tear-down process.

2条回答
  •  情书的邮戳
    2020-12-05 15:15

    viewDidUnload will not be called every time like dealloc method. viewDidUnload is called only when your app receives low memory warning!

    Just think, if you are releasing your object both in viewDidUnload and dealloc methods. If both gets called every time, then you are releasing already released object, which will lead to application crash, isn't it?. viewDidUnload is a place provided by the Apple for cleaning up the things when receiving the low memory warning because you know in iPhone we have memory restriction.

提交回复
热议问题