Let say i have an class named as MyTestClass.h.
Class structure is look like
@interface MyTestClass : NSObject {
NSString *testString;
}
@property (nonatomic, retain)NSString * testString;
@end
.m file
@implementation MyTestClass
@synthesize testString;
-(id) init{
[self setTestString:@""];
return self;
}
-(void)dealloc{
[self.testString release];
testString = nil;
[super dealloc];
}
@end
Now i created an object of MyTestClass and assigned testString twice
MyTestClass * myTestClass = [[MyTestClass alloc] init];
[myTestClass setTestString:@"Hi"];
[myTestClass setTestString:@"Hello"];
Now i think, two times my testStrings memory is leaked!! (one through init() and another one through my first setTestString method)
Am i correct? or will @property (nonatomic, retain) handle/release previous allocated memory?
or ,in this kind of cases ,will i need to override the setTestString() in MyTestClass.m like below code
-(void)setTestString:(NSString *)tempString{
[testString release];
testString = nil;
testString = [tempString retain];
}
Any help on this question is appreciated.
Thanks.