如果我有一個實例方法,並在此方法中我做這樣的事情:的Objective-C:當不分配的對象得到釋放
NSString *peopleString = [peopleList componentsJoinedByString: @", "];
...
UILabel *likeLabel = [[UILabel alloc] initWithFrame:CGRectMake(16.0+6.0f, 4.0f, 252.0f, 12.0f)];
[likeLabel setText:peopleString];
[likeLabel setFont:[UIFont fontWithName:@"Arial" size:12]];
[likeRow addSubview:likeLabel];
[likeLabel release];
的componentsJoinedByString
不包含new
,copy
或alloc
,因此我不必釋放它。我想知道的是,當我的peopleString被取消分配時。可能會發生早?意思是,在我可以在我的標籤中設置文字之前。我應該更好地使用[[NSString alloc] initWithString:[peopleList componentsJoinedByString: @", "]];
並在此方法結束時發佈它嗎?
感謝您的回答,並指出我#6578 – znq 2010-05-05 09:48:22