Note that there are some explanatory texts on larger screens.

plurals
  1. POCreating gradient and returning for a method
    primarykey
    data
    text
    <p>Sorry for noobish question about iPhone and Quartz programming. Just started my conversion from C++ to Objective-C :)</p> <p>So, I have such a class method</p> <pre><code>+(CGGradientRef)CreateGradient:(UIColor*)startColor endColor:(UIColor*)endColor { CGGradientRef result; CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); CGFloat locations[2] = {0.0f, 1.0f}; CGFloat startRed, startGreen, startBlue, startAlpha; CGFloat endRed, endGreen, endBlue, endAlpha; [endColor getRed:&amp;endRed green:&amp;endGreen blue:&amp;endBlue alpha:&amp;endAlpha]; [startColor getRed:&amp;startRed green:&amp;startGreen blue:&amp;startBlue alpha:&amp;startAlpha]; CGFloat componnents[8] = { startRed, startGreen, startBlue, startAlpha, endRed, endGreen, endBlue, endAlpha }; result = CGGradientCreateWithColorComponents(colorSpace, componnents, locations, 2); CGColorSpaceRelease(colorSpace); return result; } </code></pre> <p>and its usage.</p> <pre><code>-(void)FillGradientRect:(CGRect)area startColor:(UIColor *)startColor endColor:(UIColor *)endColor isVertical:(BOOL)isVertical { CGContextRef context = UIGraphicsGetCurrentContext(); UIGraphicsPushContext(context); CGGradientRef gradient = [Graphics CreateGradient:startColor endColor:endColor]; CGPoint startPoint, endPoint; if (isVertical) { startPoint = CGPointMake(CGRectGetMinX(area), area.origin.y); endPoint = CGPointMake(startPoint.x, area.origin.y + area.size.height); }else{ startPoint = CGPointMake(0, area.size.height / 2.0f); endPoint = CGPointMake(area.size.width, startPoint.y); } CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0); CGGradientRelease(gradient); UIGraphicsPopContext(); } </code></pre> <p>everything works as expected. But, when I run the Analyze tool from Xcode 4, I'm getting a warning about memory leak in method <strong>CreateGradient</strong> for <code>result</code> variable. Well, I understand what's that about, but in my calling method I'm releasing the gradient object (<code>CGGradientRelease(gradient);</code>). So, who is wrong and how to make Analyze tool happy? </p> <p>Thx</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload