Code Example: Why can I still access this NSString object after I've released it?

前端 未结 3 1411
生来不讨喜
生来不讨喜 2021-01-20 10:34

I was just writing some exploratory code to solidify my understanding of Objective-C and I came across this example that I don\'t quite get. I define this method and run th

3条回答
  •  滥情空心
    2021-01-20 11:27

    The retainCount always printing one is probably caused by optimization - when release notices that its going to be deallocated, there's no reason to update the retainCount to zero (as at this point nobody should have a reference to the object) and instead of updating the retainCount just deallocates it.

提交回复
热议问题