0

I've been searching around but haven't found a clear answer if Core Graphic primitives (CGMutablePathRef, CGPath, gradients, etc.) need to be released when using ARC (+ iOS6).

I've seen this (silence a compiler warning about releasing a CGMutablePathRef object) and a few other questions but they are either out of date or not entirely clear (to me at least).

Community
  • 1
  • 1
spring
  • 18,009
  • 15
  • 80
  • 160

1 Answers1

3

Yes.

Roughly said, only NSObject instances are handled through ARC. ARC is a compiler mechanism that adds release/retain for you when needed. So, it only applies in cases where you could use release/retain in the non-ARC case.

This does not include either memory allocated through malloc, nor low-level frameworks (core graphics, core audio, etc.). Specifically, objects allocated through low-level frameworks need to be released by using specific methods (e.g., CGImageRelease, etc.).

EDIT:

A very specific case of Core Foundation data types are toll-free bridged types. In pre-ARC world you could safely specify a CF data type where its correspondent Objective-C class was expected (e.g., CFString in place of NSString). ARC forbids this since ownership semantics would not be clear. Thus, a set of ARC directives are available to specify that ownership information (see this for more info), but this is not the case of CGPath, which is not toll-free bridged (since it is not stated in CGPath Reference).

By the way, a great resource for all ARC-doubts is this rich post of Mike Ash's.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • 1
    +1 Note that toll-free bridged CF classes can be brought under ARC's control using bridged casts. – Andrew Madsen Mar 06 '13 at 18:13
  • @Andrew Madsen: thanks. I added the relevant info to my answer for completeness, although it does no apply to OP's case. – sergio Mar 06 '13 at 18:24