2

I have table with Images cell. Images download from internet and save in local disk. Count = 200. Tableview show this images. When scroll content to bottom, comes message memory warning... Used memory 250 - 300 mb O_O!!! Links to images that do not keep.

NSString *cellID = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
...
NSString* imagePath = [arrayContent objectAtIndex:indexPath.row];
UIImage* image = [[UIImage alloc] initWithContentsOfFile:imagePath];
[cell.imageView setImage:image];

Why hide images not release?

4

2 回答 2

6

替换此行

UIImage* image = [[UIImage alloc] initWithContentsOfFile:imagePath];

用这个检查一次

 UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
于 2013-10-16T12:00:53.687 回答
0

好吧,我使用了一个自定义MSAsyncImageCell类,它在被 iOS 重用时替换其图像。它从 URL 异步加载图像,优雅地显示“正在加载”的图像,并在重新用于另一个图像时释放内存。如果你愿意,我可以在这里发布代码,但代码有点长。

这是实际加载图像的代码部分。我有来自网络/缓存的图像,所以它是 NSData。

- (BOOL)_loadImageWithData:(NSData *)imageData
{
    UIImage *image = [UIImage imageWithData:imageData];

    // Just in case loading failed.

    if (image)
    {
        // Extra check - don't mix up.
        if ([[self.currentURL absoluteString] isEqualToString:[self.imageURL absoluteString]])
            self.asyncImageView.image = image;

        return YES;
    }

    return NO;
}
于 2013-10-16T11:47:25.980 回答