0

我的应用程序出现内存警告,然后它崩溃了。这个错误,我认为是在我的触摸绘图功能上,因为当我尝试使用 alloc 工具运行它时,当我继续在屏幕上移动手指时,内存开始增加。

这是我的代码。

    touchSwiped = YES;

    UITouch *touch = [touches anyObject];

    previousPoint2 = previousPoint1;
    previousPoint1 = currentTouch;
    currentTouch = [touch locationInView:self.view];

    CGPoint mid1 = midPoint(previousPoint2, previousPoint1); 
    CGPoint mid2 = midPoint(currentTouch, previousPoint1);

    UIGraphicsBeginImageContext(CGSizeMake(480 , 320));
    [drawView.image drawInRect:CGRectMake(0, 0, 480,320)];  

    CGContextRef context = UIGraphicsGetCurrentContext();    

    CGContextSetLineCap(context,kCGLineCapRound);
    CGContextSetLineWidth(context, inkWidth);
    CGContextSetBlendMode(context, blendMode);
    CGContextSetRGBStrokeColor(context,redColor, greenColor, blueColor, 1);
    CGContextBeginPath(context);
    CGContextMoveToPoint(context, mid1.x, mid1.y);
    CGContextAddQuadCurveToPoint(context, previousPoint1.x, previousPoint1.y, mid2.x, mid2.y);
    CGContextStrokePath(context);

    drawView.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsGetCurrentContext();
4

2 回答 2

2

使用时UIGraphicsBeginImageContext,应始终与用UIGraphicsEndImageContext完后平衡,否则清理不干净。按照您的方法运行的代码仍然会认为当前的 UI 上下文是您手动发布的,可能会带来灾难性的后果。

于 2012-08-14T07:35:07.477 回答
-2

我做了 Ohr 在他的评论中所说的,它对我有用。

我发布了CGContextRef这样的CGContextRelease(context);

于 2012-08-14T05:37:24.100 回答