我從SDK分析的代碼塊和基礎的那種錯誤在我的最新問題的答案:對象的潛在泄漏存入
dasblinkenlight建議我創建NSData對象爲能釋放我uint8_t *字節...
但這裏在此代碼:
/**
* this will set the brush texture for this view
* by generating a default UIImage. the image is a
* 20px radius circle with a feathered edge
*/
-(void) createDefaultBrushTexture{
UIGraphicsBeginImageContext(CGSizeMake(64, 64));
CGContextRef defBrushTextureContext = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(defBrushTextureContext);
size_t num_locations = 3;
CGFloat locations[3] = { 0.0, 0.8, 1.0 };
CGFloat components[12] = { 1.0,1.0,1.0, 1.0,
1.0,1.0,1.0, 1.0,
1.0,1.0,1.0, 0.0 };
CGColorSpaceRef myColorspace = CGColorSpaceCreateDeviceRGB();
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
CGPoint myCentrePoint = CGPointMake(32, 32);
float myRadius = 20;
CGContextDrawRadialGradient (UIGraphicsGetCurrentContext(), myGradient, myCentrePoint,
0, myCentrePoint, myRadius,
kCGGradientDrawsAfterEndLocation);
UIGraphicsPopContext();
[self setBrushTexture:UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
我得到了相同類型的錯誤在這些線路上:
存儲到 'myColorspace' 對象的潛在泄漏
CGGradientRef myGradient = CGGradientCreateWithColorComponents (myColorspace, components, locations, num_locations);
存儲到 'myGradient' 對象的潛在泄漏
UIGraphicsPopContext();
我試圖與:
free(myColorspace);
free(myGradient);
但我保持同樣的問題,我能做些什麼來解決它
在此先感謝您的支持
只需添加名稱中帶有「創建」或「複製」的任何Apple函數即可返回+1對象。請參閱http://developer.apple.com/library/ios/#DOCUMENTATION/CoreFoundation/Conceptual/CFMemoryMgmt/CFMemoryMgmt.html#//apple_ref/doc/uid/10000127i – jsd
@jsd同意的重要信息。 –