iphone memory management: alloc and retain properties.

Posted by Jonathan on Stack Overflow See other posts from Stack Overflow or by Jonathan
Published on 2010-12-28T17:35:12Z Indexed on 2010/12/28 17:54 UTC
Read the original article Hit count: 183

According to the docs, you do one release per alloc or retain (etc) However what about when using retain propertys?

eg:

HEADER
@property(retain)UIView *someView;

IMPLEMENTATION
/*in some method*/
UIView *tempView = [[UIView alloc] init]; //<<<<<ALLOC - retain count = +1
[tempView setBackgroundColor:[UIColor redColor]];
self.someView = tempView; ///<<<<<RETAIN - retain count = +2
[tempView release];   ///should I do this?

or a different version of the IMPLEMENTATION

self.someView = [[UIView alloc] init]; //<<<<<ALLOC & RETAIN - retain count = +2
//now what??? [self.someView release]; ????

EDIT: I didn't make it clear, but I meant what to do in both circumstances, not just the first.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c