Difference between release and release then set to nil

前端 未结 5 1793
粉色の甜心
粉色の甜心 2020-12-29 17:14

What is the difference between two snippets?

[myObj release];

and

[myObj release];
myObj = nil;
5条回答
  •  伪装坚强ぢ
    2020-12-29 17:54

    You have to be careful with the first one, because after you release, the pointer still points to some garbaged memory and can contains some other object. So, in the first one, if you try [myObj release] then [myObj doSomething], the application can crash

    My advice is that you should always set it to nil after you release.

提交回复
热议问题