views:

38

answers:

1

Hi again, i've just mad Build and Analyze with my project on iphone, and i got warning from analyzer which i don't understand, this is my function:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

 [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

 NSLog(@"user did select row at index: %d.%d", [indexPath section], [indexPath row]);
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
 NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);

 //UIView *customView;

 if(section ==6){


  UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 36.0)];

  UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  headerLabel.backgroundColor = [UIColor clearColor];
  headerLabel.opaque = NO;
  headerLabel.textColor = [UIColor whiteColor];
  headerLabel.highlightedTextColor = [UIColor whiteColor];
  headerLabel.shadowColor = [UIColor blackColor];
  headerLabel.shadowOffset = CGSizeMake(0, 1);
  headerLabel.font = [UIFont boldSystemFontOfSize:13];
  headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 30.0);
  headerLabel.text = @"Personal Data"; 
  [customView addSubview:headerLabel];

  return customView;

 }
 if(section ==10){


  UIView *customView = [[UIView alloc] initWithFrame:CGRectMake(10.0, 0.0, 300.0, 36.0)];

  UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  headerLabel.backgroundColor = [UIColor clearColor];
  headerLabel.opaque = NO;
  headerLabel.textColor = [UIColor whiteColor];
  headerLabel.highlightedTextColor = [UIColor whiteColor];
  headerLabel.shadowColor = [UIColor blackColor];
  headerLabel.shadowOffset = CGSizeMake(0, 1);
  headerLabel.font = [UIFont boldSystemFontOfSize:13];
  headerLabel.frame = CGRectMake(10.0, 0.0, 300.0, 30.0);
  headerLabel.text = @"Actions"; 
  [customView addSubview:headerLabel];
  [headerLabel release];

  return customView;

 }
 else {
     return nil;
   }

    NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);     
}

and in the lines with return customView, the analyzer says: "potential leak of an object allocated in line ###", can somebody explain me why it's hapenning?

Thank for help

A: 

You need:

return  [customView autorelease];

You allocate your customView and don't release it anywhere in your code. Once you pass it to table view it will get retained so you can safely dispose of its ownership - by sending autorelease message.

P.S. you also forgot to release headerLabel in section == 6 branch

Vladimir