CGMutablePathRef中的内存泄漏

时间:2014-10-24 02:25:25

标签: ios objective-c sprite-kit

我在SKScene的每次更新中画一条线。然而,最终尽管我发布了每个创建的行,但应用程序仍然崩溃。我曾经把CGMutablePathRef作为实例变量保存,并在它变得太大时释放它。我更改了它以支持可变数组,因为我认为它会修复内存问题。它没有。

有什么想法吗?此功能是我创建和发布

的唯一地方
-(void)update:(CFTimeInterval)currentTime {
    if (![_currentlyRunning isEqual:@""] && canMove && !_dead) {
        if (!linePoints) {
            linePoints = [[NSMutableArray alloc] init];
        }
        [linePoints enqueue:[NSValue valueWithCGPoint:CGPointMake(_robot.position.x, _robot.position.y)]];
        if ([linePoints count] > 200) [linePoints dequeue];
    }
    if (linePoints) {
        CGMutablePathRef line = CGPathCreateMutable();

        for(int i = 0; i < [linePoints count]; ++i) {
            CGPoint p = [linePoints[i] CGPointValue];
            if(i == 0) {
                CGPathMoveToPoint(line, NULL, p.x, p.y);
            } else {
                CGPathAddLineToPoint(line, NULL, p.x, p.y);
            }
        }
        [lineLayer removeFromParent];
        lineLayer = nil;
        lineLayer = [SKShapeNode node];
        lineLayer.path = line;
        CGPathRelease(line);
        lineLayer.lineWidth = 7;
        lineLayer.alpha = .2;
        [lineLayer setStrokeColor:[UIColor blackColor]];
        [self addChild:lineLayer];
    }
}

0 个答案:

没有答案