基本的な描画アプリを作成しています。実際のデバイスでテストするまでは、すべて問題なく動作していると思いました。iPad mini で使用すると、描画中にメモリ不足のクラッシュが発生しますが、シミュレーターではそのような問題はありません。実機で描画しているとメモリ使用量が急上昇するのを見ることができますが、シミュレータでは同じ現象が再現できず、奇妙なことです。以下に、描画に使用しているコードを投稿しました。これを引き起こしているものはありますか?どうすればメモリ使用量を減らすことができますか? ありがとうございました。
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
mouseSwiped = YES;
if ([eraserButtonStatus isEqual: @"OFF"]) {
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView: self.mainImage];
UIGraphicsBeginImageContext(self.mainImage.frame.size);
[self.tempImage.image drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height)];
// CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),NO);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), thickness );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red,green,blue, thickness);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempImage setAlpha:1.0];
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}
else{
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView: self.mainImage];
UIGraphicsBeginImageContext(self.mainImage.frame.size);
[self.tempImage.image drawInRect:CGRectMake(0, 0, self.mainImage.frame.size.width, self.mainImage.frame.size.height)];
CGContextSetAllowsAntialiasing(UIGraphicsGetCurrentContext(),NO);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), thickness );
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), red,green,blue, thickness);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.tempImage.image = UIGraphicsGetImageFromCurrentImageContext();
[self.tempImage setAlpha:1.0];
UIGraphicsEndImageContext();
lastPoint = currentPoint;
}}