title: memory leak in cell with UILabel with ARC
body: <p>Hi i have problem with my app with memory leak on UILabel in cells on table view. Every time if I enter to table view and back, memory rise with 2mb, and if I enter to that view again it rise with next 2mb. Why I know that is because of UILabel :
  - I checked it with profiler:zombies and
  - If I remove UILabels from cell, I hadn't memory leaks</p>
  
  <p>For start I defined my cell:</p>
  
  <pre><code>@interface ExpandableTableViewCell : UITableViewCell{
      BOOL hasData;
  
      NSString *documentTypeId;
      NSString *documentId;
      UILabel *label;
      UILabel *dayAndMonthLabel;
      UILabel *yearLabel;
      UIButton *iconButton;
  
      UILabel *firstLineLabel;
      UILabel *firstLineValue;
  
      UILabel *secondLineLabel;
      UILabel *secondLineValue;
  
      UILabel *thirdLineLabel;
      UILabel *thirdLineValue;
  
      UILabel *fourthLineLabel;
      UILabel *fourthLineValue;
  
      UILabel *fifthLineLabel;
      UILabel *fifthLineValue;
  }
  
  - (void) setLabelValue: (NSString*) value;
  - (void) setDayAndMonthValue: (NSString*) value;
  - (void) setYearValue: (NSString*) value;
  - (void) setFirstLineLabelValue: (NSString*) value;
  - (void) setFirstLineValue: (NSString*) value;
  - (void) setSecondLineLabelValue: (NSString*) value;
  - (void) setSecondLineValue: (NSString*) value;
  - (void) setThirdLineLabelValue: (NSString*) value;
  - (void) setThirdLineValue: (NSString*) value;
  - (void) setFourthLineLabelValue: (NSString*) value;
  - (void) setFourthLineValue: (NSString*) value;
  - (void) setFifthLineLabelValue: (NSString*) value;
  - (void) setFifthLineValue: (NSString*) value;
  
  - (void) openCell;
  - (void) closeCell;
  
  - (UIButton*) getIconButton;
  
  @property (nonatomic) BOOL hasData;
  @property (nonatomic) NSString *documentTypeId;
  @property (nonatomic) NSString *documentId;
  
  @end
  </code></pre>
  
  <p>And init method looks like: </p>
  
  <pre><code>- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  {
      self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
      if (self) {
          self.backgroundColor = [UIColor whiteColor];
          self.clipsToBounds = true;
          [self setHasData: NO];
          [self setSelectionStyle:UITableViewRowAnimationBottom];
          [self setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
  
          iconButton = [UIButton buttonWithType:UIButtonTypeCustom];
          [iconButton setFrame: CGRectMake(6, 24, 30, 30)];
          [iconButton setBackgroundColor: [UIColor clearColor]];
          [iconButton setImage:[UIImage imageNamed:@"invoiceIcon.png"] forState:UIControlStateNormal];
          [iconButton setImage:[UIImage imageNamed:@"invoiceIcon.png"] forState:UIControlStateDisabled];
          [iconButton setEnabled: YES];
          [iconButton addTarget:self action:@selector(buttonPress:) forControlEvents:UIControlEventTouchDown];
          [iconButton  addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchUpInside];
          [iconButton  addTarget:self action:@selector(buttonRelease:) forControlEvents:UIControlEventTouchUpOutside];
  
          label = [[UILabel alloc] initWithFrame:CGRectMake(42, 4, 250, 16)];
          [label setBackgroundColor:[UIColor clearColor]];
          [label setTextColor: [UIColor  colorWithRed:105.0/255.0 green:154.0/255.0 blue:64.0/255.0 alpha:1.0]];
          [label setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16.0]];
  
          // creation date
          dayAndMonthLabel = [[UILabel alloc] initWithFrame:CGRectMake(266, 4, 50, 10)];
          [dayAndMonthLabel setBackgroundColor:[UIColor clearColor]];
          [dayAndMonthLabel setTextColor: [UIColor lightGrayColor]];
          [dayAndMonthLabel setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
          [dayAndMonthLabel setTextAlignment:NSTextAlignmentRight];
  
  
          yearLabel = [[UILabel alloc] initWithFrame:CGRectMake(266, 17, 50, 10)];
          [yearLabel setBackgroundColor:[UIColor clearColor]];
          [yearLabel setTextColor: [UIColor lightGrayColor]];
          [yearLabel setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
          [yearLabel setTextAlignment:NSTextAlignmentRight];
          //------
  
          // 1 ----
          firstLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 26, 90, 14)];
          [firstLineLabel setBackgroundColor:[UIColor clearColor]];
          [firstLineLabel setTextColor: [UIColor  colorWithRed:73.0/255.0 green:107.0/255.0 blue:196.0/255.0 alpha:1.0]];
          [firstLineLabel setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
          firstLineValue = [[UILabel alloc] initWithFrame:CGRectMake(42, 44, 250, 14)];
          [firstLineValue setBackgroundColor:[UIColor clearColor]];
          [firstLineValue setTextColor: [UIColor  darkGrayColor]];
          [firstLineValue setFont:[UIFont fontWithName:@"Helvetica" size: 14.0]];
          [firstLineValue setTextAlignment:NSTextAlignmentLeft];
  
          // 2 ----
          secondLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 62, 90, 14)];
          [secondLineLabel setBackgroundColor:[UIColor clearColor]];
          [secondLineLabel setTextColor: [UIColor  colorWithRed:73.0/255.0 green:107.0/255.0 blue:196.0/255.0 alpha:1.0]];
          [secondLineLabel setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
          secondLineValue = [[UILabel alloc] initWithFrame:CGRectMake(98, 62, 180, 14)];
          [secondLineValue setBackgroundColor:[UIColor clearColor]];
          [secondLineValue setTextColor: [UIColor  darkGrayColor]];
          [secondLineValue setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
          [secondLineValue setTextAlignment:NSTextAlignmentRight];
  
          // 3 ----
          thirdLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 80, 90, 14)];
          [thirdLineLabel setBackgroundColor:[UIColor clearColor]];
          [thirdLineLabel setTextColor: [UIColor  colorWithRed:73.0/255.0 green:107.0/255.0 blue:196.0/255.0 alpha:1.0]];
          [thirdLineLabel setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
          thirdLineValue = [[UILabel alloc] initWithFrame:CGRectMake(98, 80, 180, 14)];
          [thirdLineValue setBackgroundColor:[UIColor clearColor]];
          [thirdLineValue setTextColor: [UIColor  darkGrayColor]];
          [thirdLineValue setFont:[UIFont fontWithName:@"Helvetica" size:14.0]];
          [thirdLineValue setTextAlignment:NSTextAlignmentRight];
  
          // 4 ----
          fourthLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 96, 90, 13)];
          [fourthLineLabel setBackgroundColor:[UIColor clearColor]];
          [fourthLineLabel setTextColor: [UIColor  colorWithRed:73.0/255.0 green:107.0/255.0 blue:196.0/255.0 alpha:1.0]];
          [fourthLineLabel setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
          fourthLineValue = [[UILabel alloc] initWithFrame:CGRectMake(98, 96, 180, 13)];
          [fourthLineValue setBackgroundColor:[UIColor clearColor]];
          [fourthLineValue setTextColor: [UIColor  darkGrayColor]];
          [fourthLineValue setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
          [fourthLineValue setTextAlignment:NSTextAlignmentRight];
  
          // 5 ----
          fifthLineLabel = [[UILabel alloc] initWithFrame:CGRectMake(42, 109, 90, 13)];
          [fifthLineLabel setBackgroundColor:[UIColor clearColor]];
          [fifthLineLabel setTextColor: [UIColor  colorWithRed:73.0/255.0 green:107.0/255.0 blue:196.0/255.0 alpha:1.0]];
          [fifthLineLabel setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
          fifthLineValue = [[UILabel alloc] initWithFrame:CGRectMake(98, 109, 180, 13)];
          [fifthLineValue setBackgroundColor:[UIColor clearColor]];
          [fifthLineValue setTextColor: [UIColor  darkGrayColor]];
          [fifthLineValue setFont:[UIFont fontWithName:@"Helvetica" size:13.0]];
          [fifthLineValue setTextAlignment:NSTextAlignmentRight];
  
          [self.contentView addSubview: iconButton];
          [self.contentView addSubview: label];
  
          [self.contentView addSubview: dayAndMonthLabel];
          [self.contentView addSubview: yearLabel];
  
          [self.contentView addSubview: firstLineLabel];
          [self.contentView addSubview: firstLineValue];
          [self.contentView addSubview: secondLineLabel];
          [self.contentView addSubview: secondLineValue];
          [self.contentView addSubview: thirdLineLabel];
          [self.contentView addSubview: thirdLineValue];
          [self.contentView addSubview: fourthLineLabel];
          [self.contentView addSubview: fourthLineValue];
          [self.contentView addSubview: fifthLineLabel];
          [self.contentView addSubview: fifthLineValue];
  
      }
      return self;
  }
  </code></pre>
  
  <p>exaple setter method looks:</p>
  
  <pre><code>- (void) setFirstLineValue: (NSString*) value
  {
      [firstLineValue setText:value];
  }
  </code></pre>
  
  <p>and in my view I had cellForRowAtIndexPath looks:</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"DOCUMENT_LIST_CELL";
  
      ExpandableTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
      if(cell == nil){
          cell = [[ExpandableTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
          cell.documentTypeId = [NSString stringWithFormat:@"%@", fisDocumentTypeId ];
          if(indexPath.item &gt;= start &amp;&amp; indexPath.item &lt;= end){
              [cell setHasData:TRUE];
          } else {
              UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
              spinner.frame = CGRectMake(148, 27, 24, 24);
              spinner.tag = 1234567;
              [cell setHasData:FALSE];
              [cell.contentView addSubview: spinner];
              [spinner startAnimating];
          }
      } else {
          id viewToRemove = [cell.contentView viewWithTag:1234567];
          [viewToRemove removeFromSuperview];
          viewToRemove = nil;
  
          if(indexPath.item &gt;= start &amp;&amp; indexPath.item &lt;= end){
              [cell setHasData:TRUE];
          } else {
              UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
              spinner.frame = CGRectMake(148, 27, 24, 24);
              spinner.tag = 1234567;
              [cell setHasData:FALSE];
              [cell.contentView addSubview: spinner];
              [spinner startAnimating];
          }
      }
  
      if(indexPath.item &gt;= start &amp;&amp; indexPath.item &lt;= end){
          NSMutableDictionary *dataDict = [documentListData objectAtIndex: (indexPath.item - start)];
          NSDate *localizedDate = [isoDateFormatter dateFromString:[dataDict valueForKey:@"creationDate"]];
          [cell setLabelValue: [dataDict valueForKey:@"identifier"] != [NSNull null] ? [dataDict valueForKey:@"identifier"] : [dataDict valueForKey:@"id"] ];
          cell.documentId = [NSString stringWithFormat:@"%@",[dataDict valueForKey:@"id"] ];
          [cell setDayAndMonthValue: [dayAndMonthFormatter stringFromDate:localizedDate] ];
          [cell setYearValue: [yearFormatter stringFromDate:localizedDate] ];
  
          for(int i = 0; i &lt; 5; i++){
              if( [dataDict objectForKey: [NSString stringWithFormat:@"line%i",i ] ] != nil ){
                  NSMutableDictionary *lineDict = [dataDict objectForKey: [NSString stringWithFormat:@"line%i",i ] ];
  
                  switch (i) {
                      case 0:
                          [cell setFirstLineLabelValue: [lineDict objectForKey:@"field"]];
                          [cell setFirstLineValue: [[NSString stringWithFormat:@"%@", [lineDict objectForKey:@"value"]]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ];
                          break;
                      case 1:
                          [cell setSecondLineLabelValue: [lineDict objectForKey:@"field"]];
                          [cell setSecondLineValue: [[NSString stringWithFormat:@"%@", [lineDict objectForKey:@"value"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ];
                          break;
                      case 2:
                          [cell setThirdLineLabelValue: [lineDict objectForKey:@"field"]];
                          [cell setThirdLineValue: [[NSString stringWithFormat:@"%@", [lineDict objectForKey:@"value"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ];
                          break;
                      case 3:
                          [cell setFourthLineLabelValue: [lineDict objectForKey:@"field"]];
                          [cell setFourthLineValue: [[NSString stringWithFormat:@"%@", [lineDict objectForKey:@"value"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ];
                          break;
                      case 4:
                          [cell setFifthLineLabelValue: [lineDict objectForKey:@"field"]];
                          [cell setFifthLineValue: [[NSString stringWithFormat:@"%@", [lineDict objectForKey:@"value"]] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ];
                          break;
                      default:
                          break;
                  }
              }
          }
  
      } else {
          [cell setLabelValue: @""];
          [cell setDayAndMonthValue: @""];
          [cell setYearValue: @""];
          [cell setFirstLineLabelValue: @""];
          [cell setFirstLineValue: @""];
          [cell setSecondLineLabelValue: @""];
          [cell setSecondLineValue: @""];
          [cell setThirdLineLabelValue: @""];
          [cell setThirdLineValue: @""];
          [cell setFourthLineLabelValue:@""];
          [cell setFourthLineValue:@""];
          [cell setFifthLineLabelValue:@""];
          [cell setFifthLineValue:@""];
      }
  
  
      return cell;
  }
  </code></pre>
  
  <p>EDIT ------------
  For request of Alok, I'm puting code of creating view:</p>
  
  <pre><code>DocumentListViewController *documentListView = [[DocumentListViewController alloc] initWithStyle:UITableViewStylePlain documentTypeId:documentTypeId documentTypeName:translation documentTypeIcon:nil documentTypeCode: code andSyncField:syncField andSyncFieldTranslation:syncFieldTrans documentTypeData:documentTypeData];
      documentListView.hidesBottomBarWhenPushed = YES;
      [self.navigationController pushViewController:documentListView animated:YES];
  </code></pre>
  
  <p>And I do nothink in view/controler when I touch bac button, only I have:</p>
  
  <pre><code>- (void)viewWillDisappear:(BOOL)animated
  {
      [self.navigationController setToolbarHidden:YES animated:NO];
      [super viewWillDisappear:animated];
  }
  </code></pre>