Skip to content

Commit f923993

Browse files
committed
Fixing memory leak
(CGColorRef) CGColor { CGFloat components[4] = {(CGFloat)_r, (CGFloat)_g, (CGFloat)_b, (CGFloat)_a}; return CGColorCreate(CGColorSpaceCreateDeviceRGB(), components); } CGColorSpaceCreateDeviceRGB() returns a Core Foundation object with +1 retain count and this object is not referenced later and has a retain count of +1.
1 parent c743e77 commit f923993

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cocos2d/Support/CCColor.m

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,14 @@ - (CCColor*) initWithUIColor:(UIColor *)color
170170
}
171171
#endif
172172

173+
/// After using you must call CGColorRelease(color)
173174
- (CGColorRef) CGColor
174175
{
175176
CGFloat components[4] = {(CGFloat)_r, (CGFloat)_g, (CGFloat)_b, (CGFloat)_a};
176-
return CGColorCreate(CGColorSpaceCreateDeviceRGB(), components);
177+
CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
178+
CGColorRef color = CGColorCreate(colorspace, components);
179+
CGColorSpaceRelease(colorspace);
180+
return color;
177181
}
178182

179183
#ifdef __CC_PLATFORM_IOS

0 commit comments

Comments
 (0)