Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7651215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:27:02+00:00 2026-05-31T11:27:02+00:00

UPDATE: This issue has been fixed as of Xcode 4.6! This technique now works

  • 0

UPDATE: This issue has been fixed as of Xcode 4.6!

This technique now works as intended again. However, make sure to read the notes at the top of Rob Napier’s excellent answer before you use it in your code.

ORIGINAL POST

(ARC, Xcode 4.3.1, iOS 5.1)

I have a strong property of a CF type (CGImage) that I want to be automatically managed by ARC using __attribute__((NSObject)) (as in having retain & release in the synthesized setter, and it being nil’ed in dealloc), but it doesn’t work: the object is not retained when I assign the property.

A minimal example to reproduce:

@interface TestClass : NSObject
@property (nonatomic, strong) __attribute__((NSObject)) CFStringRef str;
@end

// ...In some function
CFStringRef str = (__bridge CFStringRef)[NSString stringWithFormat:@"%g", 2.5];
NSLog(@"%ld", CFGetRetainCount(str));
TestClass *obj = [[TestClass alloc] init];
obj.str = str;
NSLog(@"%ld", CFGetRetainCount(str));

Which prints ‘1’ twice.

Now the strange thing is that (although I’m not sure of this) I think it worked properly before I updated to iOS 5.1 & Xcode 4.3.1 (from iOS 5 & Xcode 4.2), and with it switched from gdb to lldb. Can someone who hasn’t upgraded (or knows how to change back the compiler) perhaps confirm?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:27:03+00:00Added an answer on May 31, 2026 at 11:27 am

    EDIT2 (Mar 2013) FYI for those interested in this technique, ARC documentation for clang includes the following note:

    The use of __attribute__((NSObject)) typedefs is not recommended. If it’s absolutely necessary to use this attribute, be very explicit about using the typedef, and do not assume that it will be preserved by language features like __typeof and C++ template argument substitution.

    Rationale

    Any compiler operation which incidentally strips type “sugar” from a type will yield a type without the attribute, which may result in unexpected behavior.


    EDIT The below is interesting, but probably irrelevant. This is a bug and you should open a radar. As noted by @lnafziger, this is legal and is supposed to be honored. The bug is that it is not honored when you include nonatomic. If you remove nonatomic, then it works. Nothing in the nonatomic definition suggests that this is by design.


    This is kind of clever, but I think I see why it isn’t working. You can confirm, btw, that it isn’t working by generating the assembler and noting that setStr: does not call objc_storeStrong(). It does a simple assign.

    The problem is that your property definition does not conform to the definition of a retainable object pointer (emphasis added):

    A retainable object pointer (or retainable pointer) is a value of a
    retainable object pointer type (retainable type). There are three
    kinds of retainable object pointer types:

    • block pointers (formed by applying the caret (^) declarator sigil to a
      function type)
    • Objective-C object pointers (id, Class, NSFoo*, etc.)
    • typedefs marked with __attribute__((NSObject))

    Did you create a typedef as specified? No you did not. OK, so how would we do this?

    typedef __attribute__((NSObject)) CFStringRef MYStringRef;
    
    @interface TestClass : NSObject
    @property (nonatomic, strong) MYStringRef str;
    @end
    
    ... the rest of your code ...
    

    This will print “1” and then “2” as I assume you expect. Scares me for unspecified reasons, but looking at the assembler output, everything seems fine and I can’t think of any specific problem or violation here.

    You could be justified in opening a radar for this. The fact that a typedef is not treated the same as a specified type is surprising at least, even if documented.

    EDIT: Noting @lnafziger’s comment from the ObjC Programming Language, there is definitely either an error in the ARC spec/implementation or an error in the linked document, so one of them should be fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This issue has been resolved. you can read about the solution in here:
My development team of four people has been facing this issue for some time
I have been fighting this issue for days now and about to beat my
Well, this architectural issue has been wandering in my mind for a while. Suppose
I know this has been answered here before, however even after following all the
Update: This bug has been confirmed by at least two others. Even if you
Update: this question has been answered (see below). I'll leave it up in case
Update: This issue was not properly explored. The real issue lies within render :json
I have this exact issue ASP.net can’t update page from event handler and it's
UPDATE: this is a repost of How to make shell scripts robust to source

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.