2016-01-15 130 views
1

我的应用程序是使用以下代码绘制阴影时“的对象的潜在泄漏”:使用核心图形

-(void)drawShadow:(CGContextRef)context rect:(CGRect)rect{ 

    CGContextSaveGState(context); 

    //Set color of current context 
    [[UIColor blackColor] set]; 

    //Set shadow and color of shadow 
    CGContextSetShadowWithColor(context, CGSizeMake(0, 2), 3, [[UIColor colorWithWhite:0 alpha:0.5] CGColor]); 

    CGContextFillEllipseInRect(context, rect); 

    CGContextClipToMask(context, rect, CGBitmapContextCreateImage(context)); 

    CGContextRestoreGState(context); // Warning shows in this line 

} 

当运行产品>分析,它标志着该块与该消息的最后一个指令:“潜在的物体泄漏”。当我删除该行时,它显示相同的消息,但在右括号中。

任何想法我做错了什么?

感谢

回答

0

chedabob的回答工作!以下是最终代码:

-(void)drawShadow:(CGContextRef)context rect:(CGRect)rect{ 
    CGContextSaveGState(context); 
    //Set color of current context 
    [[UIColor blackColor] set]; 
    //Set shadow and color of shadow 
    CGContextSetShadowWithColor(context, CGSizeMake(0, 2), 3, [[UIColor colorWithWhite:0 alpha:0.5] CGColor]); 
    CGContextFillEllipseInRect(context, rect); 

    CGImageRef bitmap = CGBitmapContextCreateImage(context); 
    CGContextClipToMask(context, rect, bitmap); 
    CGContextRestoreGState(context); 

    CGImageRelease(bitmap); 
}