Kyle_at_QP
Kyle_at_QP

Reputation: 153

Difference in releasing the CGColorSpaceRef by calling CFRelease versus using CGColorSpaceRelease?

Suppose I'm using CGColorSpaceRef. I'm wondering if there is a difference between releasing the CGColorSpaceRef by calling CFRelease versus using CGColorSpaceRelease?

i.e., a difference between this:

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

// do stuff

CFRelease(colorspace);

versus doing:

CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

// do stuff

CGColorSpaceRelease(colorspace); 

Upvotes: 1

Views: 683

Answers (2)

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43472

Either is acceptable. The second one will check for NULL however, so it lets you skip a line of code. You must always check for NULL before calling CFRelease(). If you don't and NULL is passed in, it will crash.

Upvotes: 2

torrey.lyons
torrey.lyons

Reputation: 5589

From the CGColorSpace Reference:

This function is equivalent to CFRelease, except that it does not cause an error if the cs parameter is NULL.

Upvotes: 5

Related Questions