如何删除内存警告级别= 2

时间:2011-10-13 10:28:47

标签: ios4

 - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
 {

     UITouch *firstTouch = [touches anyObject];
     CGPoint firstPoint = [firstTouch locationInView:drawImage];

     NSLog(@"drawimage retain coount touches began: %i",[drawImage retainCount]);

     lastPointX = firstPoint.x;
     lastPointY = firstPoint.y;
 }

- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
 {

     UITouch *touch = [touches anyObject]; 
     CGPoint movePoint = [touch locationInView:drawImage];

     UIGraphicsBeginImageContext(drawImage.frame.size);
     [drawImage.image drawInRect:drawImage.bounds];

     CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
     CGContextSetLineWidth(UIGraphicsGetCurrentContext(), value);
     CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), t1, t2, t3, 1);
     CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPointX, lastPointY);
     CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), movePoint.x, movePoint.y);
     CGContextStrokePath(UIGraphicsGetCurrentContext());
     CGContextFlush(UIGraphicsGetCurrentContext());

     drawImage.image = UIGraphicsGetImageFromCurrentImageContext();


     lastPointX = movePoint.x;
     lastPointY = movePoint.y;

     NSLog(@"drawimage retain coount touches moved: %i",[drawImage retainCount]);

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event 
{

    UITouch *touch = [touches anyObject]; 
    CGPoint movePoint = [touch locationInView:drawImage];
    UIGraphicsBeginImageContext(drawImage.frame.size);
    [drawImage.image drawInRect:drawImage.bounds];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), value);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), t1, t2, t3, 1);
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPointX, lastPointY);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), movePoint.x, movePoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    CGContextFlush(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();



    NSLog(@"drawimage retain coount touches end: %i",[drawImage retainCount]);



}

这里我的内存警告级别= 2。如何删除该警告?

1 个答案:

答案 0 :(得分:1)

retainCount没用。不要打电话。

  

这里我的内存警告级别= 2。我怎么能删除它   警告?

分配较少的内存或释放已分配的内存。 :)

在分配工具下运行您的应用并重现问题。然后检查以确切地查看正在分配和未释放的对象(或者正在分配的内容是巨大的)。

显示的代码可能是也可能不是问题;可能没有,但没有更多的背景就无法分辨。