문제

I got the following code line:

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

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

Potential 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().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top