Difference between release and release then set to nil

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

What is the difference between two snippets?

[myObj release];

and

[myObj release];
myObj = nil;
5条回答
  •  灰色年华
    2020-12-29 18:05

    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 :)

提交回复
热议问题