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.
精彩评论