我目前看到内存泄漏的问题,它似乎来自这段代码:
- (void)drawRect:(CGRect)rect
{
CGImageRef cgImage = CGBitmapContextCreateImage(offScreenBuffer);
UIImage *uiImage = [[UIImage alloc] initWithCGImage:cgImage];
CGImageRelease(cgImage);
[uiImage drawInRect:self.bounds];
[uiImage release];
}
该方法是从触摸事件调用的...
-(void)drawPoint:(UITouch *)touch {
currentLoc = [[PointLocation alloc] init];
currentLoc.location = [touch locationInView:self];
self.previousPoint = self.point;
self.point = currentLoc;
[self drawToBuffer];
[currentLoc release];
}
这是绘制到缓冲区......
-(void)drawToBuffer {
CGFloat color[4] = {R,G,B,A};
if (self.previousPoint != nil) {
CGContextSetRGBStrokeColor(offScreenBuffer, color[0],color[1],color[2],color[3]);
CGContextBeginPath(offScreenBuffer);
CGContextSetLineWidth(offScreenBuffer, lane);
CGContextSetLineCap(offScreenBuffer, kCGLineCapRound);
CGContextMoveToPoint(offScreenBuffer, previousPoint.location.x, previousPoint.location.y);
CGContextAddLineToPoint(offScreenBuffer, point.location.x, point.location.y);
CGContextDrawPath(offScreenBuffer, kCGPathStroke);
}
[self setNeedsDisplay];
}
这真的很慢....:( 我不知道为什么...
每次我在选定的视图中绘制时,都会调用此方法,但每次我需要创建图像并将其显示在屏幕上时。有没有可能以另一种方式做到这一点?