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

后端 未结 2 1838
深忆病人
深忆病人 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 14:53

    It is quite thoughtful that, viewDidiUnload method get only called when memory warning appears. Good practise would be to release requisite the object within this method and also make the object nil.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题