开发者

Is releasing a property

开发者 https://www.devze.com 2023-01-24 16:26 出处:网络
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:

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

精彩评论

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