Object sent - autorelease too many times, getting

2019-07-29 22:56发布

问题:

I am getting too many Object sent - autorelease too many times, this memory leak for my iPhone app and dont know how to resolve it http://screencast.com/t/fPzMNewvq Above is screen shot for the same.

SAAdvertiseCell has lot of objects which are releasing, so how is it possible to find where the exact problem is? Thanks

回答1:

At first why don't you reuse cells?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    Cell* cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
    if(!cell)
    {
        cell = // create new cell;
    }

    // configure cell

    return cell;
}

And for your problem: seems that initWithData: already returns an autoreleased object, then you send another autorelease. So check that method to find the problem.



回答2:

For creation of Custom UITableViewCell, write your code in this manner:

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

      if (cell == nil) {
          NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"MyTableViewCell" owner:self options:nil];
         cell = [topLevelObjects objectAtIndex:0];    
      }

      // write your code to customize cell or providing data content

      return cell;
}

Hope this will help you to solve your problem