2016-01-15 131 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); 
}