Suppose if i want to erase a 开发者_运维知识库value stored in a NSString
variable, i will assign a nil
to it. This is possible. But if i want to erase a date variable that already holds some values, what should i do?
nil
is just an object placeholder. You can assign any Objective-C object pointer to it.
So yeah, you can assign a variable of type NSDate *
to nil
.
If you have ownership of the object however, you should send it the -release
message before setting the variable to nil
or else the memory pointed to by the variable will be leaked.
you can... but it is advisable to release it if it is not autorelease object..
i.e
[dateObject release]; // Only if it is not autorelease object.
dateObject = nil;
精彩评论