I have an NSString which has been declared as property and being allocated and initialised in view did load as below:
NSString *textWithKey;
@property(nonatomic,retain)NSString *textWithKey;
in .m i have
@synthesize textWithKey;
and in viewDidLoad i have
self.textWithKey=[[NSString alloc]init];
self.textWithKey=@"";
Now somewhere in my code i am using
self.textWithKey=[self.textWithKey stringByAppendingString:text1];
it works fine untill another method is called which returns different values.
and from there on this perticularline is called again but debugger shows textWithKey out of scope.I have not released textWihKey any where.
Yes that’s right. You did not release it. But you also didn’t allocate it. 😉 At first you called
self.textWithKey = [[NSString alloc] init]. Than you callself.textWithKey = @"". Because you use the setters for the property, the old assigned value is released every time. Try the following:Because
is the same as
And there you don’t allocate anything. 😉