Do I need to free CGColorSpaceRef under ARC?

Say I have this piece of code:

CGColorSpaceRef colorSpaceRGB = CGColorSpaceCreateDeviceRGB(); CGContextSetStrokeColorSpace(context, colorSpaceRGB); CGContextSetFillColorSpace(context, colorSpaceRGB); 

After that I draw a picture. When I'm done, do I need to manually free colorSpaceRGB if I use ARC? Like this:

 CGColorSpaceRelease(colorSpaceRGB); 

Or do I need to do anything?

Thanks:)

+6
source share
3 answers

Yes. According to Apple's document: because the CGColorSpaceRelease function is equivalent to CFRelease, except that it does not cause an error if the cs parameter is NULL. And if you create, copy, or explicitly save a Core Foundation object, you are responsible for freeing it when you no longer need it (see Memory Programming Guide for Core Foundation).

+10
source

Yes, I think so, even in ARC.

You need to call CGColorSpaceRelease in accordance with the CGColorSpace Documentation documentation .

+3
source

Update for Swift 4.0:

This is no longer needed in current versions of Swift.

 CGColorSpaceRelease(colorSpace) 

The following message appears in this line of code:

"CGColorSpaceRelease" is not available: Core Foundation objects are automatically memory managed.

0
source

Source: https://habr.com/ru/post/918882/


All Articles