Objective-C: when does an assigned object get deallocated

Posted by Stefan Klumpp on Stack Overflow See other posts from Stack Overflow or by Stefan Klumpp
Published on 2010-05-04T14:45:30Z Indexed on 2010/05/04 14:48 UTC
Read the original article Hit count: 247

If I have a instance method and within this method I do something like this:

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];

The componentsJoinedByString doesn't contain a new, copy or alloc, thus I don't have to release it. What I'm wondering though is, when my peopleString gets deallocated. Might it happen to early? Meaning, before I can set the text in my label. Should I better use a [[NSString alloc] initWithString:[peopleList componentsJoinedByString: @", "]]; and release it at the end of this method?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-management