Objective-C Difference between setting nil and releasing

前端 未结 4 1365
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 22:55

I\'ve learned that in dealloc you do [object release]; but in viewDidUnload (in a UIViewController subclass) you do self.object

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 23:39

    If you just release an object, then it will become freed object.

    And if you try to perform any sort of operation on freed object then your app crashes. To avoid such accidents, it is always preferred "assign your object to nil after releasing it". Because we all know any operations performed on nil will not be executed :)

提交回复
热议问题