where is the memory leak
I have a line of code:
CGFloat *components = CGColorGetComponents([color CGColor]);
and the analyzer is saying that there is a leak here. I tried free(components) but the app crashes when I do that. Is there really a leak here since I didnt allocate anything. I know that CGColorGetComponents returns an array of 3 CGFloat's but when I try to free them开发者_StackOverflow社区 it crashes.
Any help is appreciated.
See SO #792119.
Declaring the variable does not create the array. In fact, neither does CGColorGetComponents. Whatever created the CGColor object created the array and stored it inside the object; CGColorGetComponents lets you have the pointer to that storage.
In short, do not free your pointer.
You could, however, set it to NULL.
Maybe you should pass color.CGColor as argument? Have a look at this thread: What does CGColorGetComponents() return?
精彩评论