cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

CCColor memory leak

Open slxl opened this issue 10 years ago • 3 comments

I'm using SpriteBuilder 1.3.6 with Xcode 6.1.1 (6A2008a) Bug is reproduced on my iPhone 4s with iOS 7.1.1 (no more devices available now).

Steps to reproduce: Just create for instance CCLabelTTF as usual

floatingScoreLabel = [CCLabelTTF labelWithString:@"0"
                                        fontName:@"fontname.fnt" 
                                        fontSize:13
[self addChild:floatingScoreLabel];

And there is a leakage occurs. Instrument's leakage tool points to

2015-01-17 16 54 17

Possible fix: Adding _CGColorRelease(color); before line #183 removes the leakage

slxl avatar Jan 17 '15 10:01 slxl

I have the same problem. Thanks slxl, your fix works for me too.

aalzanki avatar Apr 15 '15 19:04 aalzanki

Looks like this is what @slembcke was referring to in https://github.com/cocos2d/cocos2d-spritebuilder/pull/1303#issuecomment-93494449

As CCColor are immutable there is no need to keep re-allocating the _color - once it has been created it can stay the same, which is what https://github.com/cocos2d/cocos2d-spritebuilder/pull/1303 does.

[If a CCMutableColor (please no!) is ever added then it needs revisiting!]

richardgroves avatar Apr 15 '15 21:04 richardgroves

Looks like https://github.com/cocos2d/cocos2d-spritebuilder/issues/1168#issuecomment-93544371 was the previous discussion/proposed fix.

richardgroves avatar Apr 15 '15 21:04 richardgroves