I have a tableview that has a string on the last row.
@interface MyTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
{
NSString *loadingMessage;
}
@property (retain) NSString *loadingMessage;
@synthesize loadingMessage;
- (UITableViewCell *)tableView:(UITableView *)pTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//some stuff...
cell.textLabel.text = loadingMessage;
}
Then when some event happens, I will be changing the loading message:
-(void)requestFailed:(NSError*)error {
self.loadingMessage = [NSString stringWithFormat:@"Failed with error: %@", error];
}
According to instruments I am leaking the loadingMessage string in here… But I don’t see why. I thought the count for stringWithFormat is +0, and the setter is +1. I release the string when I dealloc as well. What am i doing wrong?
The code you posted is correct. Indeed,
stringWithFormatreturns an autoreleased object, so you can assign it directly to a retained property.So, either you are doing some other assignment in your code, or, more probably, you are not releasing
loadingMessagein yourdealloc.Just an hypothesis.