CFSTR memory management

I use the CFSTR function to create a CFString from the constant string c, and I often call this function in my Daemon.

From documentation :
The value returned by CFSTR has the following semantics:

  • Values ​​returned from CFSTR are not output by CFString - they are guaranteed to be valid until the program terminates .
  • You can keep the release values ​​returned from CFSTR in a balanced way, such as any other CFString, but you are not required to.

Should I use save and release?

+6
source share
1 answer

As stated in the documentation, CFSTR() created lines remain valid until the program terminates. You can release them all day, but they will not actually be released. For this reason, there is no need to explicitly save / free them. It is true to save / release them, because otherwise you could not pass them through another code that saves / releases them (structure methods, etc.). Treat them as if you created NSString literals created using @"" , that is, you do not need to save or release them after creation, but if you write code that can accept any CFString, you need to follow the normal rules for memory management , including the use of CFRetain() and CFRelease() .

+11
source

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


All Articles