开发者

-(void)dealloc and property(nonatomic, retain)

开发者 https://www.devze.com 2023-04-01 12:02 出处:网络
I have declared some two labels in .h file and also declare @property(nonatomic,retain)UILabel *label1;

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

0

精彩评论

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

关注公众号