Как я могу удалить уровень предупреждения памяти = 2 - PullRequest
0 голосов
/ 13 октября 2011
 - (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 Ответ

1 голос
/ 13 октября 2011

retainCount бесполезно.Не называйте это.

Здесь я получаю предупреждение об уровне памяти = 2.Как я могу удалить это предупреждение?

Выделите меньше памяти или освободите выделенную память.:)

Запустите приложение под инструментом Allocations Instrument и воспроизведите проблему.Затем проверьте, чтобы точно увидеть, какие объекты выделяются, а не освобождаются (или что выделяется, что огромно).

Показанный код может быть или не быть проблемой;вероятно нет, но невозможно сказать без контекста.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...