cellForRowAtIndexPath中对象的潜在泄漏

Stu*_*ntX 0 objective-c ios automatic-ref-counting xcode4.5

我收到以下代码的上述违规行为:

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

    UITableViewCell *cell = [tableView   dequeueReusableCellWithIdentifier:simpleTableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
    }



        cell.textLabel.text = [mapContacts objectAtIndex:indexPath.row];
    NSLog(@"%@",cell.textLabel.text);
    cell.detailTextLabel.text = [number objectAtIndex:indexPath.row];



        return cell;


}
Run Code Online (Sandbox Code Playgroud)

违规行为显示return cell;可以采取哪些措施来解决这个问题?请帮忙.我正在使用带有ARC的XCode 4.5.

Mar*_*rio 6

你显然没有使用ARC(至少在那个编译单元/文件中).

这个:

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];
Run Code Online (Sandbox Code Playgroud)

导致手动引用计数(=非ARC)中的(潜在)泄漏.您需要在此行的末尾添加自动释放:

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier] autorelease];
Run Code Online (Sandbox Code Playgroud)

或者只是确保ARC已正确启用(在构建阶段查找-fno-objc-arc标志)