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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:16:03+00:00 2026-06-08T08:16:03+00:00

Mike Ash says: When __bridge_transfer is used in a cast, it tells ARC that

  • 0

Mike Ash says:

When __bridge_transfer is used in a cast, it tells ARC that this object is already retained, and that ARC doesn’t need to retain it again. Since ARC takes ownership, it will still release it when it’s done.

Clang documentation says:

(__bridge_transfer T) op casts the operand, which must have non-retainable pointer type, to the destination type, which must be a retainable object pointer type. ARC will release the value at the end of the enclosing full-expression, subject to the usual optimizations on local values.

Nowhere in the Clang documentation does it say that __bridge_transfer avoids a double retain. It only says that the object is released sometime in the future.

Why does this matter? Consider the following code snippet:

NSString *value = (__bridge_transfer NSString *)CFPreferencesCopyAppValue(CFSTR("someKey"), CFSTR("com.company.someapp"));

The CFStringRef starts out with a retainCount of +1. When it is assigned to value, the CFStringRef is retained again because, by default, value is strongly referenced. This results in a double retain. At the end of the scope, a -release is sent to value, but nothing else exists to balance the lingering retain from CFPreferences*Copy*AppValue, resulting in a memory leak.

How does __bridge_transfer avoid a double retain?

  • 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-06-08T08:16:05+00:00Added an answer on June 8, 2026 at 8:16 am

    Clang’s documentation agrees with Mike Ash. It says it performs a cast, and the object is released at the end of the scope. There is no retain performed during the cast.

    Basically, (__bridge_transfer T) causes the value to be treated as an already-owned value of type T, just as how calling [T new] would return an already-owned value of type T.

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

Sidebar

Related Questions

Mike Ash has written this introduction to ARC where he introduces something like: __weak
I came accross this on the Mike Ash Care and feeding of singletons and
I have a file that looks like this ID Name Car 1 Mike Honda
This question is in regards to Mike Bostock's very exciting d3.js library in general,
As I went through this wonderful blog by Mike McCandless explaining the power of
I have a string like this: $a = Mike , Tree ; I want
I'm new to scala. I tried this code: val name = mike println(name.getClass()) It's
This works as expected: SELECT Mike AS FName This fails with the error Query
is there in VB.NET something like this in php?: $var[a1]['name']=Mike; $var[a1]['nick']=MMM; I tried hashtables,
I have a similar problem as @Mike in this question . The question is

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.