0
votes

this may be a simple question but i can't figure the solution.Im creating a custom cell for a table view.When I'm testing the app instruments is showing leaks in code used for creating custom cell.I don't understand where i have to release the stuff for removing the leaks.Can anyone give me a hand for this. This is the code i used for creating the custom cell.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID= @"Parcustom";
    Parcustom *cell = (Parcustom *)[tableView dequeueReusableCellWithIdentifier:cellID];

    if(cell==nil)
    {


        NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"Parcustom" owner:nil options:nil];

        for(id currentObject in nibObjects)
        {
            if([currentObject isKindOfClass: [Parcustom class]])
            {
                cell = (Parcustom *)currentObject;
            }

        }
    }    // Configure the cell...
        cell.f1.text=[datedisplay objectAtIndex:indexPath.row];




           cell.f2.text=[tips objectAtIndex:[[indexx objectAtIndex:indexPath.row]intValue]];
                  cell.selectionStyle=UITableViewCellSelectionStyleGray;             
    return cell;

}

The instrument is saying leak in the line NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"Parcustom" owner:nil options:nil]; How can i remove this leak.Can anyone help me please.

3

3 Answers

1
votes

Replace below code with if block

NSArray *nibObjects = [[NSArray alloc] initWithArray:[[NSBundle mainBundle] loadNibNamed:@"Parcustom" owner:nil options:nil]];

    for(id currentObject in nibObjects)
    {
        if([currentObject isKindOfClass: [Parcustom class]])
        {
            cell = (Parcustom *)currentObject;
        }

    }
    [nibObjects release];
0
votes

It seems there is no leak in the code presented. I suppose actual leak is somewhere in Parcustom class. Perhaps you don't release some ivar in Parcustom's dealloc. Maybe f1 or f2.

0
votes

I don't see a leak in your code - Try running the static analyzer ("Analyze" in XCode's menu) and see if it reports a leak. If it does, you can expand the information about the leak and see the root cause.