2013-03-08 26 views
1

我不確定何時在下面的代碼示例中釋放由CGPathCreateMutable創建的路徑。何時發佈CGMutablePathRef

// iVar 
    ivarImageView = [[UIImageView alloc] initWithImage:nil]; 

    // Clip to shape 
    CALayer *imageLayer = [self.ivarImageView layer]; 
    CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 
    CGMutablePathRef clipPath = CGPathCreateMutable(); 
    shapeLayer.path = clipPath; 
    imageLayer.mask = shapeLayer; 

    [self addSubview:self.ivarImageView]; 

iVarImageView是保留的伊娃。所以它被用於對象的生命,就像它的shapLayer.path一樣。那麼什麼時候才能發佈這條路?

回答

1

可以行後釋放:

shapeLayer.path = clipPath; 

既然你分配給shapeLayer.path,你不擔心以後的clipPath因爲它會通過shapeLayer擁有。