Rodrigo
Rodrigo

Reputation: 12714

Run time check of ARC (Automatic Reference Counting)

How can I check if my program is running in an ARC (Automatic Reference Counting) device?

I can use this code:

#if ! __has_feature(objc_arc)
#    define FMDBRelease(__v) ([__v release]);
#else
#    define FMDBRelease(__v)
#endif

But this work in compile time. A easy code for this is:

if ([object respondsToSelector:@selector(release)]) {
    [object release];
}

But not work. I am not finding it in any place. There are a solution for this?

Upvotes: 1

Views: 2039

Answers (2)

Jonathan Grynspan
Jonathan Grynspan

Reputation: 43470

You can't. ARC is a compile-time tool. It has no real presence at runtime, except for the insertion of calls that allow for tail-call optimization.

Upvotes: 3

hypercrypt
hypercrypt

Reputation: 15376

ARC is a compile time technology, thus the #if __has_feature(objc_arc) way is the correct way of doing this.

Upvotes: 5

Related Questions