// ClassA.m
NSString *strA = [[NSstring alloc] initWithString:@"test string"];
ClassB *classB = [[ClassB alloc] init];
[classB setStrB:strA];
[strA release];
// classB will be released later
// ClassB.h
@property (nonatomic, retain) NSString *strB;
// ClassB.m
// custom setter
-(void) setStrB:(NSString *)newStr {
strB = newStr;
}
Will strB leak? Should it be released in ClassB dealloc method?
Yes you have to add a release in the ClassB dealloc cause you make a retain on strB in the setter.
Object “strB” life :