ArchiveOrangemail archive

Objective-C/C++ language development discussion list


objc-language.lists.apple.com
(List home) (Recent threads) (100 other Apple lists)

Subscription Options

  • RSS or Atom: Read-only subscription using a browser or aggregator. This is the recommended way if you don't need to send messages to the list. You can learn more about feed syndication and clients here.
  • Conventional: All messages are delivered to your mail address, and you can reply. To subscribe, send an email to the list's subscribe address with "subscribe" in the subject line, or visit the list's homepage here.
  • Low traffic list: less than 3 messages per day
  • This list contains about 4,584 messages, beginning Oct 2009
  • 0 messages added yesterday
Report the Spam
This button sends a spam report to the moderator. Please use it sparingly. For other removal requests, read this.
Are you sure? yes no

memory management with and without ARC

Ad
Greg Robbins 1313192288Fri, 12 Aug 2011 23:38:08 +0000 (UTC)
Is there a good approach to writing shared source code that may need to be
compiled in applications with and without ARC, short of wrapping retain,
release, autorelease, and other MRR & ARC-specific keywords in macros?
Greg Parker 1313193007Fri, 12 Aug 2011 23:50:07 +0000 (UTC)
On Aug 12, 2011, at 4:37 PM, Greg Robbins wrote:
> Is there a good approach to writing shared source code that may need to be compiled in applications with and without ARC, short of wrapping retain, release, autorelease, and other MRR & ARC-specific keywords in macros?I've done some of this for the Objective-C runtime's unit tests, so the same test code builds and runs with any memory management scheme. 

My recommendation is: don't. 

Pick ARC or MRC for your shared code. Users of that shared code are not forced to make the rest of their code match your memory choice, because ARC can be enabled on a per-file basis.

You should enforce that your shared code file be compiled in the right mode. 
    #if ! __has_feature(objc_arc)
    #error This file must be compiled with ARC.
    #endif

You should be careful with the interface to your shared code such that ARC and non-ARC clients can use it freely.
* Conform to Cocoa's memory management conventions even though an all-ARC or no-ARC project would not require it
* Don't use object pointers inside C structs
* Avoid CF types-- 
Greg Parker          Runtime Wrangler
Home | About | Privacy