1

不知何故,当我滚动到表格底部(仅限 96 个项目)时,我得到 1 GB 的内存使用量(它会随着创建的每个单元格而增加。我有一个表格,其前面有一个模糊图像的图像使用带有文本的原始图像的裁剪版本。非常简单。我正在使用苹果提供的用于模糊图像的示例代码:https ://github.com/iGriever/TWSReleaseNotesView/blob/master/ TWSReleaseNotesView/UIImage%2BImageEffects.m

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"itemCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

NSDictionary *foodItem = [self.foodItems objectAtIndex:indexPath.row];

// Set up the image view
UIImageView *imageView = (UIImageView *)[cell viewWithTag:1];
UIImage *foodImage = [UIImage imageNamed:[foodItem objectForKey:FOOD_IMAGE_FILE_KEY]];
[imageView setImage:foodImage];
[imageView setContentMode:UIViewContentModeScaleAspectFill];

// Set up the label
UILabel *labelView = (UILabel *)[cell viewWithTag:2];
[labelView setFont:[UIFont flatFontOfSize:20.0]];
labelView.text = @"Blah";

// Set up the image view
UIImageView *blurredView = (UIImageView *)[cell viewWithTag:3];

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

    UIImage *blurredImage = [[self cropForBlur:foodImage] applyBlurWithRadius:4
                                                                tintColor:[UIColor colorWithWhite:1.0 alpha:0.2]
                                                    saturationDeltaFactor:1.2
                                                                maskImage:nil];

    dispatch_sync(dispatch_get_main_queue(), ^{
        blurredView.image = blurredImage;
    });
});

return cell;

}

*注意:我知道这很可能是模糊(与我的裁剪相反),因为它只在我进行模糊时发生。此外,它与异步调度无关,因为如果我不这样做,它仍然会发生。

是的,我正在使用 ARC。是的,我正在使用故事板。

这是cropForBlur:

- (UIImage *)cropForBlur:(UIImage *)originalImage
{
    CGSize size = [originalImage size];
    int startCroppingPosition = 100;
    if (size.height > size.width) {
        startCroppingPosition = size.height/2 + ((size.width / 320) * 45);
    } else {
        startCroppingPosition = size.height/2 + ((size.width / 320) * 45);
    }
    // WTF: Don't forget that the CGImageCreateWithImageInRect believes that
    // the image is 180 rotated, so x and y are inverted, same for height and width.
    CGRect cropRect = CGRectMake(0, startCroppingPosition, size.width, ((size.width/320) * 35));
    CGImageRef imageRef = CGImageCreateWithImageInRect([originalImage CGImage], cropRect);
    UIImage *newImage = [UIImage imageWithCGImage:imageRef scale:(size.width/160) orientation:originalImage.imageOrientation];
    CGImageRelease(imageRef);
    return newImage;
}

我也尝试过查看 Instruments,但它会显示我总共使用了大量内存,但大块内存并没有出现在故障中。诡异的。

这就是说我在左栏中使用大量内存。 在此处输入图像描述

这是 Instruments 中的分配位。我看不出他们怎么能匹配。我没有僵尸或任何东西(除非在编辑方案中有其他地方可以改变它)。 在此处输入图像描述

这是向下滚动一点后的泄漏仪器视图。似乎没有显示任何真正的泄漏:S 很困惑。 在此处输入图像描述

4

1 回答 1

0

请参阅此链接中的解决方案。问题是图像的比例与您的屏幕比例不同。最终输出的图像可能非常大。

于 2014-12-12T14:43:01.197 回答