0

多くのメモリリークがあります...たとえば、更新されるたびに画像が反転するUIImageViewが1つあります(アニメーションは約30fpsな​​ので、この画像はALOTを更新して反転します)

image2 = [[UIImage alloc] initWithCGImage:image2.CGImage scale:image2.scale orientation:UIImageOrientationUpMirrored];

膨大な量のメモリリークが発生しているため、一度反転した後に解放しました:

image2 = [[UIImage alloc] initWithCGImage:image2.CGImage scale:image2.scale orientation:UIImageOrientationUpMirrored];
[image2 release];

しかし、問題は、そのコードをもう一度実行しようとするとアプリがフリーズすることではありません (何かを解放してからもう一度使用することはできないと思いますか? (このメモリ割り当て全体とリリースのものにはちょっと新しい...

私は何をしますか?画像がリリースされている場合、反転する前に画像を再定義しますか? ありがとう!

4

3 に答える 3

2

おそらく最も簡単な方法は、 image2 を保持プロパティにしてからself.image2、プレーンではなくに割り当てることimage2です。これにより、新しい値が割り当てられるたびに古いイメージが解放されます。ただし、 によって行われた保持を解放するには、autorelease呼び出しに呼び出しを追加する必要があります。[UIImage alloc] init...alloc

于 2012-03-11T20:49:01.987 に答える
2

同じ変数名を再利用することで、不必要に混乱させています。一時変数を追加します。

UIImage* image; // assuming you set this up earlier, and that it's retained
UIImage* flippedImage = [[UIImage alloc] initWithCGImage:image.CGImage scale:image.scale orientation:UIImageOrientationUpMirrored];
// Now we're done with the old image. Release it, so it doesn't leak.
[image release];
// And set the variable "image" to be the new, flipped image:
image = flippedImage;
于 2012-03-11T20:50:42.677 に答える
1

画像ビューのimageプロパティを結果の画像に設定してから、割り当てられた画像を解放する必要があります。例えば:

image2 = [[UIImage alloc] initWithCGImage:image2.CGImage scale:image2.scale orientation:UIImageOrientationUpMirrored];
self.someImageView.image = image2;
[image2 release];

または、返されたイメージを自動リリースすることもできます。そのようです:

image2 = [[[UIImage alloc] initWithCGImage:image2.CGImage scale:image2.scale orientation:UIImageOrientationUpMirrored] autorelease];
self.someImageView.image = image2;

編集:あなたが何を求めているのかを明確にした後、画像を垂直方向に反転するより良い方法があります.

//lets suppose your image is already set on the image view
imageView.transform = CGAffineTransformIdentity;
imageView.transform = CGAffineTransformMakeScale(1.0, -1.0);

次に、通常に戻したい場合:

imageView.transform = CGAffineTransformIdentity;
于 2012-03-11T20:47:11.663 に答える