when i set property(retain), one "self" = one "retain"?

Posted by Walter on Stack Overflow See other posts from Stack Overflow or by Walter
Published on 2012-10-08T13:49:55Z Indexed on 2012/10/09 3:37 UTC
Read the original article Hit count: 158

although I'm about to finish my first app, I'm still confused about the very basic memory management..I've read through many posts here and apple document, but I'm still puzzled.. For example..I'm currently doing things like this to add a label programmatically:

@property (retain, nonatomic) UILabel *showTime;
@sythesize showTime;

showTime = [[UILabel alloc] initWithFrame:CGRectMake(45, 4, 200, 36)];
[self.showTime setText:[NSString stringWithFormat:@"%d", time]];
[self.showTime setFont:[UIFont fontWithName:@"HelveticaRoundedLT-Bold" size:23]];
[self.showTime setTextColor:numColor];
self.showTime.backgroundColor = [UIColor clearColor];
[self addSubview:self.showTime];
[showTime release];

this is my current practice, for UILabel, UIButton, UIImageView, etc... [Alloc init] it without self., coz I know this will retain twice.. but after the allocation, I put back the "self." to set the attributes..

My gut feel tells me I am doing wrong, but it works superficially and I found no memory leak in analyze and instruments.. can anyone give my advice? when I use "self." to set text and set background color, does it retain one automatically? THX so much!

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-management