ARC を使用して iOS 5 用のアプリを作成していますが、メモリに問題があるようです。基本的には、ディスプレイの一部のスクリーンショットを撮り、UIImage を MSMutableArray に配置してから、スクリーンショットをつなぎ合わせて 1 つの大きな画像を作成します。問題は、これを数回実行した後、メモリ使用量が多いために OS がアプリケーションを閉じることです。
UIImage をまとめたスニペットを次に示します。
UIImage* finalImage = nil;
//join the screenshot images together
UIGraphicsBeginImageContext(CGSizeMake(collage.width, collage.height));
{
int hc = 0;
for(UIImage *img in imageArr)
{
NSLog(@"drawing image at:: %i", hc);
[img drawAtPoint:CGPointMake(0, hc)];
hc+=img.size.height;
img = nil;
}
//NSLog(@"creating finalImage");
finalImage = UIGraphicsGetImageFromCurrentImageContext();
}
UIGraphicsEndImageContext();
//do something with the combined image
//remove all the objects
[imageArr removeAllObjects];
//reset class instance
[self setImageArr: [[NSMutableArray alloc] init]];
あまり多くのメモリが使用されないように、私が使用できる他の代替手段はありますか? 配列に CGImageRef を保存することはありますか? 上記のコードでメモリリークの可能性はありますか?
ヒント、指針をいただければ幸いです。
ありがとう。