0

I am using ARC in my project and it crashes when i run the app in devices so i checked command+shift+B its showing the following leak.... Below is the code which i have used,

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *CellIdentifier = @"ColourSelectTableCell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

            //CGRect frame = CGRectMake(15.0, 5.0, 25.0, cell.frame.size.height-10.0);
            selectedLabel = [[UILabel alloc] initWithFrame:CGRectMake(15.0, 5.0, 25.0, cell.frame.size.height-10.0)];
            selectedLabel.tag = kSelectedLabelTag;
            selectedLabel.font = [UIFont systemFontOfSize:24.0];
            selectedLabel.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.0]; // transparent
            [cell.contentView addSubview:selectedLabel];


            UIImageView *AtoZimage = [[UIImageView alloc] initWithFrame:CGRectMake(70, 10,60, 40)];
            UIImage *atozImage = [UIImage imageNamed:[bgArray objectAtIndex:indexPath.row]];
            AtoZimage.image = atozImage;
            [cell addSubview:AtoZimage];

            UILabel *lblTemp1 = [[UILabel alloc]initWithFrame:CGRectMake(150, 10, 190, 40)];
            lblTemp1.backgroundColor=[UIColor clearColor];
            lblTemp1.tag=kSelectedLabelTag;
            lblTemp1.text = [bgNameArray objectAtIndex:indexPath.row];
            [lblTemp1 setNumberOfLines:10];
            cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
            [lblTemp1 setFont:[UIFont boldSystemFontOfSize:16]];
            [cell addSubview:lblTemp1];


        }


        // Configure the cell...
        UIColor *cellColour = [self.bgArray objectAtIndex:indexPath.row];
        CMColourBlockView *colourView = (CMColourBlockView *)[cell viewWithTag:kcolourViewTag];
        colourView.colour = cellColour;

        selectedLabel = (UILabel *)[cell viewWithTag:kSelectedLabelTag];
        if ([self.selectedBg isEqual:cellColour]) {
            selectedLabel.text = @"✔";
        }
        else {
            selectedLabel.text = @"";
        }

        return cell;

    }

Showing memory leak as shown enter image description here

rakeshNS
  • 4,227
  • 4
  • 28
  • 42
Nithinbemitk
  • 2,710
  • 4
  • 24
  • 27

1 Answers1

0

CGRectMake has nothing to do with the leak; the leak would come from allocating the two UILabels and the UIImageView. Based on what I'm seeing, ARC is not enabled for your project, because ARC would take care of releasing your allocated objects here.

Check that ARC is enabled:

  1. Go to the Project Navigator
  2. Choose the top-level project item in the first row of the Project Navigator
  3. Under "Targets", select your app
  4. Choose "Build Settings" at the top of the editor, then search for "automatic"
  5. Locate "Objective-C Automatic Reference Counting" and set it to Yes
bneely
  • 9,083
  • 4
  • 38
  • 46