I am running the following code in tableView:cellForRowAtIndexPath:
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
I ran the leaks tool and found out that the File object is leaking because I am not releasing it. So I added the release prior to returning the cell where I thought it was safe (as shown below):
File *file = [[File alloc] init];
file = [self.fileList objectAtIndex:row];
UIImage* theImage = file.fileIconImage;
cell.imageView.image = theImage;
cell.textLabel.text = file.fileName;
cell.detailTextLabel.text = file.fileModificationDate;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
[file release];
return cell;
Now, when I run the application it crashes. Are the UITableViewCells still referencing the file object? What is the approach to use here to make sure I am not leaking memory?