【问题标题】:Object sent - autorelease too many times, getting this leak for my iPhone app?对象发送 - 自动释放太多次,让我的 iPhone 应用程序泄漏?
【发布时间】:2013-05-17 08:41:40
【问题描述】:

我发送了太多对象 - 自动释放太多次,我的 iPhone 应用程序的内存泄漏,不知道如何解决它 http://screencast.com/t/fPzMNewvq 以上是相同的屏幕截图。

SAAdvertiseCell 有很多正在释放的对象,那么如何才能找到确切的问题所在呢? 谢谢

【问题讨论】:

    标签: iphone object memory memory-leaks


    【解决方案1】:

    一开始你为什么不重复使用单元格?

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
        Cell* cell = [tableView dequeueReusableCellWithIdentifier:cell_id];
        if(!cell)
        {
            cell = // create new cell;
        }
    
        // configure cell
    
        return cell;
    }
    

    对于您的问题:似乎initWithData: 已经返回一个自动释放对象,然后您发送另一个自动释放对象。所以检查那个方法来发现问题。

    【讨论】:

      【解决方案2】:

      要创建自定义 UITableViewCell,请按以下方式编写代码:

      - (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;
      }
      

      希望这能帮助您解决问题

      【讨论】:

        猜你喜欢
        • 2011-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-09
        • 1970-01-01
        • 1970-01-01
        • 2023-03-16
        • 1970-01-01
        相关资源
        最近更新 更多