What is the difference between setting object = nil and [object release] VS [object release] and object = nil?

时光怂恿深爱的人放手 提交于 2019-12-04 17:42:58
object = nil; 
[object release]

Don't do that. You are sending a release message on a nil object that will just do nothing. But the object that was referenced by your object is still in memory because it has never received a release message.

[object release]; 
object = nil;

Here you release the object, and for convenience and security, you set nil to its reference. So you can call (by mistake of course :-) ) any method on that object and the app won't crash.

But if you use a retained property @property(nonatomic, retain), calling :

self.object = nil;

equals to call :

[object release]; 
object = nil;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!