目标C:ARC上收到内存警告

时间:2012-08-14 02:55:15

标签: objective-c ios memory automatic-ref-counting

我的应用程序出现内存警告然后崩溃了。错误,我认为是在我的触摸式功能上,因为当我尝试使用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();

2 个答案:

答案 0 :(得分:2)

使用UIGraphicsBeginImageContext时,您应该在使用完之后始终与UIGraphicsEndImageContext进行平衡,否则将无法清理它。按照您的方法运行的代码仍然会认为当前的UI上下文是您手动发布的,具有潜在灾难性结果的上下文。

答案 1 :(得分:-2)

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

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