1

どういうわけか、テーブルの一番下までスクロールすると (96 アイテムのみ)、1 GB のメモリ使用量が得られます (作成されるセルごとに増加します。前にぼやけた画像のある画像があるテーブルがあります。元の画像のトリミングされたバージョンをテキストで使用し、その上に使用します.かなりシンプルです.ここで入手可能な画像をぼかすためにAppleが提供するサンプルコードを使用しています: 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 の割り当てビットです。彼らがどのように一致するかわかりません。私はゾンビなどを持っていません(編集スキームでそれを変更する場所が他にない限り)。 ここに画像の説明を入力

少し下にスクロールした後のリークInstrumentsビューです。実際のリークは見られないようです :S とても混乱しています。 ここに画像の説明を入力

4

1 に答える 1

0

このリンクから解決策を参照してください。問題は、画像の縮尺が画面の縮尺と異なることです。最終的な出力画像は非常に大きくなる可能性があります。

于 2014-12-12T14:43:01.197 に答える