objective c - Why set object to nil after sending release message in Obj-C -


I see a lot of purpose-C code in which the following syntax occurs when trying to free the object from memory When they are no longer necessary

[Controller Release], Controller = Zero;

Set the variable to zero after sending the release message? Is there nothing left to free the object?

Is this an "old-school" way to work in "Old-C", or do I know more than that?

Calling release on an object does not necessarily mean that it is free going. It only reduces the number of maintenance of the object, it is not as long as the count of retaining reaches 0 and the object is free (and still, the object can be in an autoregroup pool and still It can not be completely free).

Therefore, you can leave your object, but you can still point to it and then it can be autorelaged and then you send it a message - but the object is now garbage. Is bad

Setting your pointer to a decisive point after releasing it means that you can not send a message to the Trash object. You have done that object, and whatever you say, zero , you can not do any harm.


Comments