No, calling [temp retain]
will not retain a
and b
. The typical pattern that you'll see is that a
and b
are retained in the -init
method of the class and released in the -dealloc
method, which keeps them around as long as the object is. For example:
@implementation Foo
- ( id)initWithA:( NSString * )aString andB:( NSString * )bString
{
if ( self = [ super init ]) {
a = [ aString copyWithZone:[ self zone ]];
b = [ bString copyWithZone:[ self zone ]];
}
return self;
}
- ( void )dealloc
{
[ a release ];
[ b release ];
[ super dealloc ];
}
@end
In this example, a
and b
are automatically retained as a result of the -copyWithZone:
call. You don't need to retain them yourself.