【问题标题】:Memory warning in table view image application - Lazy downloading表格视图图像应用程序中的内存警告 - 延迟下载
【发布时间】:2012-01-31 14:39:25
【问题描述】:

我正在使用惰性表下载图像并将图像保存在文件夹中。图像显示在表格视图中。

表格视图在一页中有 36 个图像,大约 10 页。

我一次又一次地收到内存警告。

谁能建议我如何解决这个问题?
因为我已经删除了所有对象,但问题还没有解决。

【问题讨论】:

  • 您必须发布一些相关代码,否则我们只是在猜测。
  • 您在使用 ARC 吗?如果不确定当它们滚动出屏幕时释放所有图像。否则你会遇到内存问题。确保您已在所有自定义视图中实施 -(void)dealloc 并发布您保留的任何内容!
  • 你试过缓存图片吗?
  • 如果您遇到内存问题(包括不使用[UIImage imageNamed:filename]),您不想想要缓存图像。如果您需要更多帮助,您需要向我们展示代码。

标签: iphone ios memory-leaks lazy-loading


【解决方案1】:

我认为你的代码有内存泄漏,你可以使用 profile(cmd + i) 来检查它, 或者你可以这样试试。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIndentifier";
    UITableViewCell *cell;

    cell = [_tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
#else
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease];
#endif
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    } else {
        [[cell.contentView viewWithTag:999] removeFromSuperview];
    }

    //imageView
    UIImage *image = [UIImage imageWithContentsOfFile:@"filePath"];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.tag = 999;
    [cell.contentView addSubview:imageView];
    [imageView release];

    return cell;
}

【讨论】:

    猜你喜欢
    • 2012-11-28
    • 2013-12-14
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-26
    • 1970-01-01
    相关资源
    最近更新 更多