Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView's memory leaking issue
    text
    copied!<p>Hi All I have a UITableView with the list of items fetched from sqllite. But there's a memory leak when rendering the view. Following is my cellForRowAtIndexPath method.</p> <pre><code>static NSString *CellIdentifier = @"BarListItemCell"; BarListItemViewCell *cell = (BarListItemViewCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier]; if (cell == nil) { NSArray * nib = [[NSBundle mainBundle] loadNibNamed:@"BarListItemViewCell" owner:self options:nil]; for (id cellObject in nib) { if ([cellObject isKindOfClass : [BarListItemViewCell class]]) { cell = (BarListItemViewCell *) cellObject; //break; } } NSString * key = [keys objectAtIndex:[indexPath section]]; NSDictionary * unit = [[barListDataSource objectForKey:key] objectAtIndex:[indexPath row]]; NSLog(@"unit count is %d", [unit retainCount]); cell.name.text = [unit objectForKey:@"name"]; cell.address.text = [unit objectForKey:@"address1"]; cell.features.text = [unit objectForKey:@"features"]; cell.logo.image = [UIImage imageWithData:[unit objectForKey:@"logo"]]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } return cell; </code></pre> <p>You can see the line "NSLog(@"unit count is %d", [unit retainCount]);". It's very strange that after viewDidLoad, the console displays 3 lines "unit count is 2" (I have 3 items in the whole screen). But when I drag the screen to let the UITableView show the next item, the console displays "unit count is 1". When the [tableView reloadData] method is called, the console displays also "unit count is 1". So it seems that the UITableView will release the datasource automatically. That's why I keeps memory reference count of unit being 2, otherwise, over releasing will happen. But the cost is that the memory occupied by unit will never be freed!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload