Hello, I was just finishing my application and I decided to check for some leaks. To my amazement two lines which did not used to have problems showed a lot of leaks:
Leak 1:
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(debug)NSLog(@"LOG [%d]%s",__LINE__,__FUNCTION__);
NSMutableDictionary *currentGame = [[[NSMutableArray alloc] init] autorelease];
NSInteger increment = [self calculateIncrementAtIndexPath:indexPath];
currentGame = [games objectAtIndex:(indexPath.row + increment)];
NSString *CellIdentifier = @"CellGame";
HangoverGameCell *cell = (HangoverGameCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[HangoverGameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[cell.labelName setText:[currentGame objectForKey:@"Name"]];
[cell.imageType setImage:[UIImage imageNamed:[[types objectAtIndex:[[currentGame objectForKey:@"Type"] intValue]] objectForKey:@"Image"]]];
[cell.imageRibbon setHidden:![[currentGame objectForKey:@"Popular"] boolValue]];
[cell.imageLove setHidden:![[currentGame objectForKey:@"Love"] boolValue]];
[cell.imageBeer setHidden:![[currentGame objectForKey:@"Beer"] boolValue]];
return cell;
}
Leak 2:
Code:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)theReuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:theReuseIdentifier]) {
self = [[[NSBundle mainBundle] loadNibNamed:@"HangoverGameCell" owner:self options:nil] lastObject];
self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameCell.png"]];
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gameCellSelected.png"]];
}
return self;
}
The leaking lines are in bold and red.
Obviously once I checked the lines and other codes that did this i changed
cell = [[HangoverGameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]
to:
cell = [[[HangoverGameCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]
which makes sense and fixes part of the leaking problem but now I have an error occurring each time I call: [tableview reloadData];
the error is the following
Code:
-[HangoverGameCell release]: message sent to deallocated instance 0x3c22010
PS: my custom cell is named "HangoverGameCell"