objective-ccocoacocoa-touchmemory-managementmanual-retain-release

Is there a quick rule to know when to release Objective-C variables?


Are there any rules of thumb when working with Objective-C that would help me understand when is the right time to release variables?


Solution

  • NARC! :)

    If you invoked a method that contains N ew, A lloc, R etain, or C opy, then you must release or autorelease. Otherwise you don't touch it.

    Of course, anything the documentation explicitly says trumps this rule.

    The other thing is that when you're dealing with C function the NARC rule still applies, but also gets the Create rule: if the function contains "create", then you're responsible for CFReleasing or freeing the returned data.