Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: memory management with and without ARC
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory management with and without ARC

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.

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     email@hidden     Runtime Wrangler

Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

 >memory management with and without ARC (From: Greg Robbins <email@hidden>)

Visit the Apple Store online or at retail locations.

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.