Question: 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?

Answer: 
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`.
When you use "transfer", ARC decrements the objects retain count at the end of what its doing - so in this case, you started with a count of 1, "value" is strong so it increments the count, but the "transfer" causes a decrement so you end up back with 1.

```
NSString *value = (__bridge_transfer NSString *)CFStringCreateMutableCopy(NULL, 1000, CFSTR("Hello World") );
NSLog(@"value retainCount %ld", CFGetRetainCount((__bridge CFTypeRef)value));
NSLog(@"Value = %@", value);

```

2012-07-23 17:45:49.421 TimeTester[75918:f803] value retainCount 1
2012-07-23 17:45:49.423 TimeTester[75918:f803] Value = Hello World