-1

メモリ リークの問題があり、1 週間前から答えが見つかりません。:(

photos 配列で 20 を超えるイメージをループします。常にメモリ警告が表示されます。

多分誰かが私の苛立たしい問題を手伝ってくれるでしょうか?

デバッグ メッセージ 「メモリ警告を受け取りました。」

私のUIViewでループ

images = [[NSMutableArray alloc] init];
for (Photo *photo in photos) {
    [images addObject:[[UIImage imageWithData:photo.image_compressed] ToSize:videoSize]];
}

ToSize メソッド

    #import "UIImage+toSize.h"

    @implementation UIImage (toSize)

    - (UIImage *)ToSize:(CGSize)newSize {

        float originalWidth = self.size.width;
        float originalHeight = self.size.height;

        float newWidth = newSize.width;
        float newHeight = newSize.height;

        float xMargin = 0.0f;
        float yMargin = 0.0f;

        float ratioWidth = (originalWidth / originalHeight) * newSize.height;
        float ratioHeight = (originalHeight / originalWidth) * newSize.width;

        // LEFT & RIGHT Margin
        if (ratioHeight > newSize.height)
        {
            // set new image size
            newWidth = ratioWidth;
            newHeight = newSize.height;

            // calculate margin
            xMargin = (newSize.width - ratioWidth) / 2;
        } else if (ratioWidth > newSize.width)
        {
            // set new image size
            newWidth = newSize.width;
            newHeight = ratioHeight;

            // calculate margin
            yMargin = (newSize.height - ratioHeight) / 2;
        }

        CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
        CGContextRef ctx = CGBitmapContextCreate(NULL, newSize.width, newSize.height,
                                                 CGImageGetBitsPerComponent(self.CGImage), 0,
                                                 colorSpace,
                                                 CGImageGetBitmapInfo(self.CGImage));

        CGContextDrawImage(ctx, CGRectMake(xMargin, yMargin, newWidth, newHeight), self.CGImage);

        CGImageRef cgimg = CGBitmapContextCreateImage(ctx);

        UIImage *img = [UIImage imageWithCGImage:cgimg scale:self.scale orientation:UIImageOrientationUp];

        CGColorSpaceRelease(colorSpace);
        CGContextRelease(ctx);
        CGImageRelease(cgimg);

        return img;
    }

@end
4

1 に答える 1

0

「メモリ警告を受信しました。」メモリ リークではありません。これは、メモリが不足していることを OS が伝えているためです。その時点で、メモリ不足に関連付けられているデリゲート メソッドが呼び出されます。

- (void)didReceiveMemoryWarning

実行中のアプリに、何も終了する必要がないように、不要なものを一掃する機会を与えるために、十分なスペースが作成されていない場合、アプリが強制終了され始めます。インストゥルメントにリークが見られない限り、これはメモリ リークではないと思います。

于 2013-10-29T07:51:54.453 に答える