开发者

ios: how to solve this memory leak warning

开发者 https://www.devze.com 2023-03-27 03:57 出处:网络
I got the following code line: mainLayer.shadowColor = CGColorCreate( CGColorSpaceCreateDeviceRGB(), components );

I got the following code line:

mainLayer.shadowColor = CGColorCreate( CGColorSpaceCreateDeviceRGB(), components );

When I run Product->Analyse in xcode it gives me the warning:

Potential 开发者_JS百科leak of an object allocated on line 176

So that means that I do not free my CGColor. Therefore I thought a good solution would be the following:

CGColorRef shadowColor = CGColorCreate( CGColorSpaceCreateDeviceRGB(), components ); 
mainLayer.shadowColor = shadowColor;
CGColorRelease( shadowColor );

But I still get the same leak warning. How do I repair the problem?


You need also to release colorspace:

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();
CGColorRef shadowColor = CGColorCreate( colorspace, components ); 
mainLayer.shadowColor = shadowColor;
CGColorRelease( shadowColor );
CGColorSpaceRelease(colorspace);


Is this:

CGColorSpaceCreateDeviceRGB()

by any change returning an object you're responsible for deallocating? I thought I remembered there being a function like CGColorSpaceRelease().

0

精彩评论

暂无评论...
验证码 换一张
取 消