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 7004841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:15:04+00:00 2026-05-27T21:15:04+00:00

I have a few questions about ARC (automatic reference counting): CFURLRef url = (__bridge

  • 0

I have a few questions about ARC (automatic reference counting):

CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath];
//Question 1: Here, I would expect the NSURL object to be autoreleased and
//therefore the CFURLRef will also be available for “a while.” Is this correct?

url = NULL;
//Question 2: Will this cause the NSURL to be released immediately?

NSURL *url = [NSURL fileURLWithPath:appPath];
url = nil;
//Question 3: Does the “url = nil” result in an immediate release of the NSURL?

NSURL *url = [[NSURL alloc] initWithString:@"/something"];
url = nil;
//Question 4: What about this?
  • 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-27T21:15:04+00:00Added an answer on May 27, 2026 at 9:15 pm
    CFURLRef url = (__bridge CFURLRef)[NSURL fileURLWithPath:appPath];
    //Question 1: Here, I would expect the NSURL object to be autoreleased and
    //therefore the CFURLRef will also be available for “a while.” Is this correct?
    

    Yes, because they’re the same object. Only the type changes; it is still the same reference to the same object.

    That said, expecting an object to continue to “be available for ‘a while’” after you release your last ownership of it is fragile. If you intend to keep using that object, own it for at least that long. Release it when you’re done with it, and no sooner.

    url = NULL;
    //Question 2: Will this cause the NSURL to be released immediately?
    
    NSURL *url = [NSURL fileURLWithPath:appPath];
    url = nil;
    //Question 3: Does the “url = nil” result in an immediate release of the NSURL?
    

    Yes and no.

    An assignment to a strong variable (and variables are implicitly strong unless otherwise specified) releases the previous value immediately and retains the new value. Each assignment of an NSURL object caused the object to be retained; each assignment of nil caused the previously-held object to be released.

    However, in both cases, the URL object may have been autoreleased by fileURLWithPath:. That autorelease, as always, comes due no sooner than the end of the autorelease pool, so the object may continue to live until then. That generally isn’t a problem, but it can occasionally pop up if you’re making a lot of objects (e.g., in a tight loop).

    As far as you’re concerned, yes, each assignment of nil releases the object that resided there before, fulfilling and ending your responsibility to that ownership.

    NSURL *url = [[NSURL alloc] initWithString:@"/something"];
    url = nil;
    //Question 4: What about this?
    

    Same here: Your assignment releases the object. And since there’s no autorelease in this one (you allocked it yourself), the object will die immediately.

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

Sidebar

Related Questions

I have a few questions about data synchronization. The architecture does not seem to
I have a few questions about Xcode and interaction with GCC 4.2.1: It doesn't
I have a few questions about this after reading the iPhone documentation on it:
I have a few questions about cross-page posting in ASP.NET: What is cross-page posting
I have a few questions about Core Location. 1) Should the user refuse permission
I have a few quick questions about the Microsoft Detours Library. I have used
I've been hearing about triggers, and I have a few questions. What are triggers?
There have been several questions over the past few days about the proper use
Ok, I have asked a few questions about different facets of trying to accomplish
I have a few questions about boost::regex: I tried an example below. 1) What

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.