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

  • SEARCH
  • Home
  • 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 6720713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:14:41+00:00 2026-05-26T09:14:41+00:00

I am new to Automatic Reference Counting with LLVM and Objective-C, and have a

  • 0

I am new to Automatic Reference Counting with LLVM and Objective-C, and have a question about returning CGImageRefs from my Objective-C function. In the days of manual reference counting, it was possible to simply cast the CGImageRef to an id, autorelease it, then return the original CGImageRef. With ARC, I am aware that you can direct the ARC system to autorelease and return your retainable object, but I do not see a way of doing this for CFTypeRefs.

Here is what I could do with ARC disabled:

- (CGImageRef)image {
    CGImageRef myImage;
    id myImageID = (id)myImage;
    [myImageID autorelease];
    return myImage;
}

So, I want to essentially create a method that, using ARC, returns a CGImageRef that is not owned by the caller. If there is a better way of doing the same thing, I am all open to ideas. I know that UIImage does something of this sort with the CGImage property.

Edit: Although disabling ARC for a specific file is a valid method of doing this, I’d prefer to use pure ARC throughout my code. This comes in handy when sharing specific code for specific files with others, since they will not need to change build settings for any given file. In order to leverage the ARC system to autorelease a CFTypeRef, you can do this:

__attribute__((ns_returns_autoreleased))
id CGImageReturnAutoreleased (CGImageRef original) {
    // CGImageRetain(original);
    return (__bridge id)original;
}

And then simply do return (__bridge CGImageRef)CGImageReturnAutoreleased(myImage) to return an autorelease’d image.

  • 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-26T09:14:41+00:00Added an answer on May 26, 2026 at 9:14 am

    UPDATE

    As of OS X 10.9 and iOS 7.0, the public SDK includes a CFAutorelease function.

    ORIGINAL

    You could create a utility function like this:

    void cfAutorelease(CFTypeRef *ref) {
        [[(id)ref retain] autorelease];
    }
    

    and put it in a file that you compile with ARC disabled. You need to pass the compiler flag -fno-objc-arc to disable ARC for that file. In Xcode 4, select your project, then the Build Phases tab. Open the Compile Sources section. Double-click the file that contains the utility function and put -fno-objc-arc in the popup box.

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

Sidebar

Related Questions

I started new project in XCode 4.2 without Automatic Reference Counting and without Use
With the new Automatic Reference Counting, do you think this will encourage new iphone
Possible Duplicate: How does the new automatic reference counting mechanism work? Can someone explain
I recently started a new project using Automatic Reference Counting (ARC). When I assigned
Without automatic reference counting you often write code like this, when adding a new
Automatic Reference Counting (ARC) introduces some new type qualifiers. I've seen __strong and __weak
For the most part with ARC (Automatic Reference Counting), we don't need to think
I have successfully automated the process of creating a new IIS website, however the
I am attempting to automate moving files from a folder to a new folder
I want to transition my App to ARC . I can change Objective-C Automatic

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.