开发者

Is releasing a property

I have a property which is declared as:

@property(nonatomic,retain) DateClass *dateClass;

I have this 开发者_运维问答piece of code where I need to copy a new instance into it:

//Do I need to release dateClass here first before assigning new instance?
self.dateClass = [self getOtherDateClass];

...
-(DateClass*) getOtherDateClass
{
  DateClass *dateClass = [[[DateClass alloc]init]autoRelease];

  return dateClass;         
}

Do I need to release self.dateClass before setting it to a new instance which is autoreleased or is the synthesized property already doing this for me?


No. A @property that's declared using retain or copy will release the old object for you, assuming you're using the synthesized setter for that property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜