Permalink
Browse files

Fixed some memory issues related with CGGradients

- Deprecated a couple of methods to follow the Apple naming guidelines.
(createNormalGradient and createSelectionGradient). Now use
newNormalGradient and newSelectionGradient instead.
- Fixed some memory management issues in some of the methods that
called the two above.
- Fixed an incorrect note in the docs (in methods createNormalGradient
and createSelectionGradient)

These changes remove all analyzer issues too.
  • Loading branch information...
1 parent ff330e3 commit 9d0604ed3c1655c6130e34156f035680918e9e24 @vicpenap committed Jul 12, 2012
@@ -198,9 +198,9 @@ - (void) drawTextsAtIndex:(int)i width:(float)width rect:(CGRect)rect span:(floa
y = y / 2;
textRect = CGRectMake(x, y, width, textSize.height);
- textSize = [self drawText:text
- basedOnLabel:self.cell.textLabel
- inRect:textRect showAsSelected:selected];
+ [self drawText:text
+ basedOnLabel:self.cell.textLabel
+ inRect:textRect showAsSelected:selected];
}
if (detailText)
@@ -214,8 +214,11 @@ - (void) drawTextsAtIndex:(int)i width:(float)width rect:(CGRect)rect span:(floa
- (void) drawBackground:(CGRect)rect
{
- if (self.cell.gradientStartColor && self.cell.gradientEndColor) {
- [PrettyDrawing drawGradient:[(PrettyTableViewCell *)self.cell createNormalGradient] rect:rect];
+ if (self.cell.gradientStartColor && self.cell.gradientEndColor)
+ {
+ CGGradientRef gradient = [(PrettyTableViewCell *)self.cell newNormalGradient];
+ [PrettyDrawing drawGradient:gradient rect:rect];
+ CGGradientRelease(gradient);
return;
}
@@ -227,16 +227,28 @@ typedef enum {
/** Returns a mask with the rounded corners. */
@property (nonatomic, readonly) CAShapeLayer *mask;
-/** Returns a new gradient with the configured selection gradient colors.
+/** Returns a new gradient with the configured selection gradient colors. */
+- (CGGradientRef) newSelectionGradient;
+
+/** Returns a new gradient with the configured normal gradient colors. */
+- (CGGradientRef) newNormalGradient;
+
+
+
+/** **Deprecated** Returns a new gradient with the configured selection gradient colors.
+
+ You have to release it after using it.
- You don't have to release it after using it.
+ @bug **Deprecated** Use newSelectionGradient: instead.
*/
-- (CGGradientRef) createSelectionGradient;
+- (CGGradientRef) createSelectionGradient __attribute__ ((deprecated,cf_returns_retained));
-/** Returns a new gradient with the configured normal gradient colors.
+/** **Deprecated** Returns a new gradient with the configured normal gradient colors.
+
+ You have to release it after using it.
- You don't have to release it after using it.
+ @bug **Deprecated** Use newNormalGradient: instead.
*/
-- (CGGradientRef) createNormalGradient;
+- (CGGradientRef) createNormalGradient __attribute__ ((deprecated,cf_returns_retained));
@end
@@ -120,14 +120,14 @@ - (CGPathRef) createRoundedPath:(CGRect)rect
}
-- (CGGradientRef) createGradientFromType:(CellBackgroundGradient)type
+- (CGGradientRef) newGradientFromType:(CellBackgroundGradient)type
{
switch (type)
{
case CellBackgroundGradientSelected:
- return [self.cell createSelectionGradient];
+ return [self.cell newSelectionGradient];
default:
- return [self.cell createNormalGradient];
+ return [self.cell newNormalGradient];
}
}
@@ -141,7 +141,7 @@ - (void) drawGradient:(CGRect)rect type:(CellBackgroundGradient)type
CGContextAddPath(ctx, path);
- CGGradientRef gradient = [self createGradientFromType:type];
+ CGGradientRef gradient = [self newGradientFromType:type];
CGPoint startPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMinY(rect));
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
@@ -585,6 +585,11 @@ - (UIColor *) backgroundColor
- (CGGradientRef) createSelectionGradient
{
+ return [self newSelectionGradient];
+}
+
+- (CGGradientRef) newSelectionGradient
+{
CGFloat locations[] = { 0, 1 };
NSArray *colors = [NSArray arrayWithObjects:(id)self.selectionGradientStartColor.CGColor, (id)self.selectionGradientEndColor.CGColor, nil];
@@ -598,6 +603,11 @@ - (CGGradientRef) createSelectionGradient
- (CGGradientRef) createNormalGradient
{
+ return [self newNormalGradient];
+}
+
+- (CGGradientRef) newNormalGradient
+{
CGFloat locations[] = { 0, 1 };
NSArray *colors = [NSArray arrayWithObjects:(id)self.gradientStartColor.CGColor, (id)self.gradientEndColor.CGColor, nil];
@@ -108,7 +108,6 @@ + (void) drawGradient:(CGGradientRef)gradient rect:(CGRect)rect
CGPoint endPoint = CGPointMake(CGRectGetMidX(rect), CGRectGetMaxY(rect));
CGContextDrawLinearGradient(ctx, gradient, startPoint, endPoint, 0);
- CGGradientRelease(gradient);
CGContextRestoreGState(ctx);
}

0 comments on commit 9d0604e

Please sign in to comment.