2011-10-13 62 views
0
- (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。我怎樣才能刪除該警告?我如何刪除內存警告級別= 2

回答

1

retainCount是無用的。別叫它。

這裏我得到的內存警告級別= 2。我怎樣才能移除 警告?

分配較少的內存或釋放您分配的內存。 :)

在分配工具下運行您的應用程序並重現該問題。然後檢查確切地看哪些對象正在被分配並且沒有被釋放(或者被分配的是什麼)。

顯示的代碼可能是也可能不是問題;可能不會,但沒有更多的上下文無法分辨。

+0

謝謝你的迴應,這裏drawImage佔用了大量的內存,當我釋放([drawImage release])這個在dealloc中,它沒有釋放,怎麼能釋放這個drawImage? –

相關問題