self.prop=nil; vs. [prop release];prop=nil;

后端 未结 1 1171
天涯浪人
天涯浪人 2020-12-21 01:55

If I am using synthesized properties, then why wouldn\'t I simply say :

self.property = nil;

This will release the ref count, and make sure

相关标签:
1条回答
  • 2020-12-21 02:02

    If you're trying to clear the value of a property anywhere but in a dealloc method, then self.property = nil; is the best way to do it. It'll handle all the memory management tasks for you, helping to prevent any issues.

    If you are in the dealloc method, than the best way to release that ivar is up for debate, but [property release]; tends to be recommended, since calling self.property may have secondary effects. In the dealloc method, calling property = nil; is not necessary.

    0 讨论(0)
提交回复
热议问题