Where is a memory leak

I have a line of code:

CGFloat *components = CGColorGetComponents([color CGColor]); 

and the analyzer says there is a leak. I tried for free (components), but the application crashes when I do this. Is there a leak here since I did not highlight anything. I know that CGColorGetComponents returns an array of 3 CGFloat, but when I try to free them, it crashes.

Any help is appreciated.

+1
memory-management memory-leaks objective-c
Jun 02 '11 at 19:26
source share
2 answers

See SO # 792119 .

A variable declaration does not create an array. In fact, no CGColorGetComponents. No matter which created object, CGColor created the array and saved it inside the object; CGColorGetComponents allows you to specify a pointer to this repository.

In short, do not free the pointer.

You can, however, set it to NULL.

+1
Jun 02 2018-11-11T00:
source share

Maybe you should pass color.CGColor as an argument? Take a look at this topic: What returns CGColorGetComponents ()?

0
Jun 02 2018-11-11T00:
source share



All Articles