iPhone - dealloc - Release vs. nil

前端 未结 5 1956
情书的邮戳
情书的邮戳 2020-11-28 21:18

Wondering if someone with experience could possibly explain this a bit more. I have seen examples of...

  [view release];

  view = nil;  

5条回答
  •  再見小時候
    2020-11-28 21:55

    I think using both is kind of safety net. With only release in place you could run in problem if you screwed reference counting management. You would release an object, giving its memory back to system but pointer would be still valid.

    With nil you are guaranteed that program will not crash since sending message to nil does nothing.

提交回复
热议问题