-(void)dealloc and property(nonatomic, retain)
I have declared some two labels in .h file and also declare
@property(nonatomic,retain)UILabel *label1;
@property(nonatomic,retain)UILabel *label2;
开发者_运维问答
how many time we have to release these label objects in dealloc. I am releasing only onece.
we have declare property so reference count will be increase and i am releasing once, where i release next. Any help is highly appreciated.
Thanks in Advanced:
just once per ivar. i would write dealloc
like this:
- (void)dealloc
{
[label1 release], label1 = nil;
[label2 release], label2 = nil;
[super dealloc];
}
you only release once in dealloc.. if you're using self.label1 = something multiple times it's good to do it like this:
[label1 release];
label1 = nil;
self.label1 = X;
provided that you have made init of label before code above
精彩评论