Rectangle 27 8

ARC does not manage C-types, of which CGImage may be considered. You must release the ref manually when you are finished with CGImageRelease(image);

+(void)setup {
    UIImage* spriteSheet = [UIImage imageNamed:@"mySpriteSheet.png"];
    CGRect rect;
    animation = [NSMutableArray arrayWithCapacity:numberOfFramesInSpriteSheet];
    int frameCount = 0;

    for (int row = 0; row < numberFrameRowsInSpriteSheet; row++) {
        for (int col = 0; col < numberFrameColsInSpriteSheet; col++) {
            frameCount++;
            if (frameCount <= numberOfFramesInSpriteSheet) {
                rect = CGRectMake(col*frameHeight, row*frameWidth, frameHeight, frameWidth);
                //store our image ref so we can release it later
                //The create rule says that any C-interface method with "create" in it's name 
                //returns a +1 foundation object, which we must release manually.
                CGImageRef image = CGImageCreateWithImageInRect(spriteSheet.CGImage, rect)
                //Create a UIImage from our ref.  It is now owned by UIImage, so we may discard it.
                [animation addObject:[UIImage imageWithCGImage:image]];
                //Discard the ref.  
                CGImageRelease(image);
            }
         }
    }
}

"The create rule says that any C-interface method with "create" in it's name returns a +1 foundation object, which we must release manually." - doh! Of course. Thanks CodaFi! Appreciated!

@Z.O. No problem. The create rule is actually a little hard to find in the docs, but it's very important when dealing with Apple's C-Interfaces. Here it is (along with the get rule).

You mean "core foundation" object, not "foundation" object, I believe...

@nielsbot If we're getting technical, then CG- prefixed structures aren't a part of Core Foundation, so I called them foundation types in line with what the documentation calls them. They follow the exact same rules though, so the terms are interchangeable.

objective c - Memory Leak with ARC - Stack Overflow

objective-c ios memory memory-leaks automatic-ref-counting
Rectangle 27 28

This is a correct, not leaking version. As you say in the comments: __bridge_transfer transfer the ownership to NSObject (NSString) and assume that the object is retained by CF Framework (the method CFURLCreateStringByAddingPercentEscapes return a retained object so this is what we need) than on the self object we don't want to perform any memory management. Hope it helps Fra

-(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding {
    return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
           (__bridge CFStringRef)self,
           NULL,
           (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
           CFStringConvertNSStringEncodingToEncoding(encoding));
}

objective c - Correct bridging for ARC? - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 28

This is a correct, not leaking version. As you say in the comments: __bridge_transfer transfer the ownership to NSObject (NSString) and assume that the object is retained by CF Framework (the method CFURLCreateStringByAddingPercentEscapes return a retained object so this is what we need) than on the self object we don't want to perform any memory management. Hope it helps Fra

-(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding {
    return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
           (__bridge CFStringRef)self,
           NULL,
           (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
           CFStringConvertNSStringEncodingToEncoding(encoding));
}

objective c - Correct bridging for ARC? - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 3

None of the core foundation data structure is dealt with ARC. Many a times this creates a problem. In these case we have to manually release the memory.

objective c - Memory Leak with ARC - Stack Overflow

objective-c ios memory memory-leaks automatic-ref-counting
Rectangle 27 5

The conventions of autoreleasing and allocing still apply in the world of ARC. The only difference is that ARC will insert extra retain/release calls to make it much harder to leak objects or access a dealloced object.

__weak NSString *str = [[NSString alloc] initWithFormat:@"%@", [NSDate date]];

The only place the object is retained (or equivalent) is the alloc. ARC will automatically insert a release command, causing it to be immediately dealloced.

Meanwhile, in this code:

__weak NSString *str = [NSString stringWithFormat:@"%@", [NSDate date]];

By convention, the return value of a convenience constructor like this must be an autoreleased object*. That means the current autoreleasepool has retained the object and will not release it until the pool is drained. You are therefore all but guaranteed that this object will exist for at least the duration of your method - although you probably shouldn't rely on this behaviour.

NSString *str = [NSString stringWithFormat:@"%@", [NSDate date]]; __weak NSString *weakStr = str;
str
weakStr
+stringWithFormat:

In ARC, the return value of a convenience constructor is not guaranteed to end up in the autorelease pool. See my answer for details and an example.

objective c - Lifetime of weak local variables with ARC - Stack Overfl...

objective-c automatic-ref-counting
Rectangle 27 194

Short answer: no, you do not have to nil out properties in dealloc under ARC.

Long answer: You should never nil out properties in dealloc, even in manual memory management.

In MRR, you should release your ivars. Nilling out properties means calling setters, which may invoke code that it shouldn't touch in dealloc (e.g. if your class, or a subclass, overrides the setter). Similarly it may trigger KVO notifications. Releasing the ivar instead avoids these undesired behaviors.

In ARC, the system automatically releases any ivars for you, so if that's all you're doing you don't even have to implement dealloc. However, if you have any non-object ivars that need special handling (e.g. allocated buffers that you need to free()) you still have to deal with those in dealloc.

Furthermore, if you've set yourself as the delegate of any objects, you should un-set that relationship in dealloc (this is the bit about calling [obj setDelegate:nil]). The note about doing this on classes that aren't compiled with ARC is a nod towards weak properties. If the class explicitly marks its delegate property as weak then you don't have to do this, because the nature of weak properties means it'll get nilled out for you. However if the property is marked assign then you should nil it out in your dealloc, otherwise the class is left with a dangling pointer and will likely crash if it tries to message its delegate. Note that this only applies to non-retained relationships, such as delegates.

This makes sense! Let me ask you this though: a common scenario I have is that I have a MyController : UIViewController class that creates and owns a UIView and also sets the view's delegate to itself. It is the sole retaining owner of that view. When the controller gets dealloc'ed, the view should then also get dealloc'ed. Does it then matter if the delegate pointer is dangling?

@emfurry: It probably doesn't, because by the time your view controller dies the view itself should not be in the view hierarchy and shouldn't be doing anything, but it's best not to make assumptions. What if the view asynchronously scheduled work to be done later, and the view itself ends up outliving its view controller by a short time (e.g. due to the asynchronous work retaining the view temporarily)? It's best to just nil out the delegate to be safe. And in fact, if the view in question is a UIWebView, the docs explicitly state you need to nil out the delegate.

@zeiteisen: No. unsafe_unretained is exactly equivalent to an assign property and is the normal behavior for delegate relationships under MRR, and these need to be nilled out.

I don't agree with statement about not using setters in dealloc with MRC. Apple doesn't recommend it but they do it in their code, too. You can actually create new problems by not using the setter. There are several big discussions about it. What is imporant is writing the setter correctly (it must behave correctly if you pass it a nil value) and sometimes watch the order of deallocation.

@Sulthan: Whether or not to use setters in dealloc is a huge can of worms, but my position basically boils down to: you want to call as little code as possible in dealloc. Setters have a tendency to include side-effects, either by overriding in subclasses, or via KVO, or other mechanisms. Side-effects in dealloc should especially be avoided like the plague. If you can possibly remove a method call from dealloc, you should do so. This is simplified down to: don't call setters in dealloc.

objective c - Do I set properties to nil in dealloc when using ARC? - ...

objective-c ios automatic-ref-counting
Rectangle 27 194

Short answer: no, you do not have to nil out properties in dealloc under ARC.

Long answer: You should never nil out properties in dealloc, even in manual memory management.

In MRR, you should release your ivars. Nilling out properties means calling setters, which may invoke code that it shouldn't touch in dealloc (e.g. if your class, or a subclass, overrides the setter). Similarly it may trigger KVO notifications. Releasing the ivar instead avoids these undesired behaviors.

In ARC, the system automatically releases any ivars for you, so if that's all you're doing you don't even have to implement dealloc. However, if you have any non-object ivars that need special handling (e.g. allocated buffers that you need to free()) you still have to deal with those in dealloc.

Furthermore, if you've set yourself as the delegate of any objects, you should un-set that relationship in dealloc (this is the bit about calling [obj setDelegate:nil]). The note about doing this on classes that aren't compiled with ARC is a nod towards weak properties. If the class explicitly marks its delegate property as weak then you don't have to do this, because the nature of weak properties means it'll get nilled out for you. However if the property is marked assign then you should nil it out in your dealloc, otherwise the class is left with a dangling pointer and will likely crash if it tries to message its delegate. Note that this only applies to non-retained relationships, such as delegates.

This makes sense! Let me ask you this though: a common scenario I have is that I have a MyController : UIViewController class that creates and owns a UIView and also sets the view's delegate to itself. It is the sole retaining owner of that view. When the controller gets dealloc'ed, the view should then also get dealloc'ed. Does it then matter if the delegate pointer is dangling?

@emfurry: It probably doesn't, because by the time your view controller dies the view itself should not be in the view hierarchy and shouldn't be doing anything, but it's best not to make assumptions. What if the view asynchronously scheduled work to be done later, and the view itself ends up outliving its view controller by a short time (e.g. due to the asynchronous work retaining the view temporarily)? It's best to just nil out the delegate to be safe. And in fact, if the view in question is a UIWebView, the docs explicitly state you need to nil out the delegate.

@zeiteisen: No. unsafe_unretained is exactly equivalent to an assign property and is the normal behavior for delegate relationships under MRR, and these need to be nilled out.

I don't agree with statement about not using setters in dealloc with MRC. Apple doesn't recommend it but they do it in their code, too. You can actually create new problems by not using the setter. There are several big discussions about it. What is imporant is writing the setter correctly (it must behave correctly if you pass it a nil value) and sometimes watch the order of deallocation.

@Sulthan: Whether or not to use setters in dealloc is a huge can of worms, but my position basically boils down to: you want to call as little code as possible in dealloc. Setters have a tendency to include side-effects, either by overriding in subclasses, or via KVO, or other mechanisms. Side-effects in dealloc should especially be avoided like the plague. If you can possibly remove a method call from dealloc, you should do so. This is simplified down to: don't call setters in dealloc.

objective c - Do I set properties to nil in dealloc when using ARC? - ...

objective-c ios automatic-ref-counting
Rectangle 27 115

Thanks Caleb exactly what was missing from every other page, bar the manual of course :-) thanks for that link.

objective c - How to enable ARC for a single file - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 59

Consider how ARC works with variables - each reference variable has a mode (implicit or explicit): strong, weak, etc. This mode let's ARC know how to handle reads and writes to that variable; e.g. for a strong variable reading requires no additional action while writing requires releasing the existing reference in the variable before it is replaced by the new one. ARC needs to know the mode of any variable in order to function.

Now consider variables that themselves are passed by reference, e.g. for your execute you'll have a call along the lines of:

NSError *myError = nil;
...
[someObject execute:&myError]; // pass the variable itself by reference, not the variables value

and the body of execute will contain an assignment along the lines of:

- (void)execute:(NSError * __autoreleasing *)error
{
   ...
   if (error != NULL)
      *error = [NSError ...]; // assign indirectly via the reference to a variable
   ...
}

Now for that indirect assignment ARC needs to know the mode of the referenced variable so it knows how to read and write. That is what the __autoreleasing is in the declaration, it tells ARC that it has been passed a reference to a variable whose mode is autoreleasing, and that tells ARC how to read and write the contents of the variable. Remove the __autoreleasing and a default mode will be assumed, and in this case I'd suggest being explicit is certainly good.

The autoreleasing mode means the variable contains a reference which is not owned, reads should retain if necessary and writes can just write. It is used mainly for variables passed by reference.

You might notice that in the example above the variable myError has mode strong (implicitly) and yet it is passed by reference as autoreleasing - the compiler handles this automatically by introducing a temporary autoreleasing variable, copying without retaining the current reference in myError into it, and passing the temporary by reference as the argument to execute:. After the call returns the compiler does a normal assignment from the temporary to myError, which results in any old reference being released and the returned one retained.

__autoreleasing

A: Well Apple's document is not specific, but the Clang documentation says it is implicit for indirect parameters. As above I'd recommend being explicit, clarity is a Good Thing.

Q: Does the placement matter?

A: Yes, and no... This is a C declaration, the stuff of quiz questions ("What does the following declare..."). The qualifier should be between the two asterisks as it is a pointer to a (variable of type) autoreleasing pointer to an object, but Apple state the compiler is "forgiving" without being specific of what it forgives. Play it safe, put it in the right place.

Q: Should you not test for error being NULL before doing the indirect assignment?

A: Of course you should, somewhere before you do the indirection. The code shown is just an outline and such detail was elided and covered by the ...s. However as it has been raised a few times over the years maybe I elided too much, a suitable if has been added.

So is __autoreleasing implicitly set if I don't explicitly set it? Also, does the placement of __autoreleasing matter (before, inside of, or after the asterisks)?

@CRD nice answer. But you might want to point out that you should check if error is NULL before assigning to *error. Otherwise, your method could crash your app since [foo execute:NULL] is a perfectly valid execution and the way to say "I don't care about the error".

It looks like in XCode 6.1, if you are not explicit, you get a warning: "Method parameter of type 'NSError *__autoreleasing *' with no explicit ownership"

Agreeing with @Joel, you want to check if error is NOT nil OR NULL before assigning *error or you could throw a EXC_BAD_ACCESS signal.

objective c - NSError and __autoreleasing - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 59

Consider how ARC works with variables - each reference variable has a mode (implicit or explicit): strong, weak, etc. This mode let's ARC know how to handle reads and writes to that variable; e.g. for a strong variable reading requires no additional action while writing requires releasing the existing reference in the variable before it is replaced by the new one. ARC needs to know the mode of any variable in order to function.

Now consider variables that themselves are passed by reference, e.g. for your execute you'll have a call along the lines of:

NSError *myError = nil;
...
[someObject execute:&myError]; // pass the variable itself by reference, not the variables value

and the body of execute will contain an assignment along the lines of:

- (void)execute:(NSError * __autoreleasing *)error
{
   ...
   if (error != NULL)
      *error = [NSError ...]; // assign indirectly via the reference to a variable
   ...
}

Now for that indirect assignment ARC needs to know the mode of the referenced variable so it knows how to read and write. That is what the __autoreleasing is in the declaration, it tells ARC that it has been passed a reference to a variable whose mode is autoreleasing, and that tells ARC how to read and write the contents of the variable. Remove the __autoreleasing and a default mode will be assumed, and in this case I'd suggest being explicit is certainly good.

The autoreleasing mode means the variable contains a reference which is not owned, reads should retain if necessary and writes can just write. It is used mainly for variables passed by reference.

You might notice that in the example above the variable myError has mode strong (implicitly) and yet it is passed by reference as autoreleasing - the compiler handles this automatically by introducing a temporary autoreleasing variable, copying without retaining the current reference in myError into it, and passing the temporary by reference as the argument to execute:. After the call returns the compiler does a normal assignment from the temporary to myError, which results in any old reference being released and the returned one retained.

__autoreleasing

A: Well Apple's document is not specific, but the Clang documentation says it is implicit for indirect parameters. As above I'd recommend being explicit, clarity is a Good Thing.

Q: Does the placement matter?

A: Yes, and no... This is a C declaration, the stuff of quiz questions ("What does the following declare..."). The qualifier should be between the two asterisks as it is a pointer to a (variable of type) autoreleasing pointer to an object, but Apple state the compiler is "forgiving" without being specific of what it forgives. Play it safe, put it in the right place.

Q: Should you not test for error being NULL before doing the indirect assignment?

A: Of course you should, somewhere before you do the indirection. The code shown is just an outline and such detail was elided and covered by the ...s. However as it has been raised a few times over the years maybe I elided too much, a suitable if has been added.

So is __autoreleasing implicitly set if I don't explicitly set it? Also, does the placement of __autoreleasing matter (before, inside of, or after the asterisks)?

@CRD nice answer. But you might want to point out that you should check if error is NULL before assigning to *error. Otherwise, your method could crash your app since [foo execute:NULL] is a perfectly valid execution and the way to say "I don't care about the error".

It looks like in XCode 6.1, if you are not explicit, you get a warning: "Method parameter of type 'NSError *__autoreleasing *' with no explicit ownership"

Agreeing with @Joel, you want to check if error is NOT nil OR NULL before assigning *error or you could throw a EXC_BAD_ACCESS signal.

objective c - NSError and __autoreleasing - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 43

As mentioned in the comments, I think it's fine to talk about ARC and the contents of Automatic Reference Counting here.

__autoreleasing is not meant to be used like that. It's used for passing indirect object references (NSError**, etc). See 4.3.4 Passing to an out parameter by writeback.

According to 3.2.4 Bridged casts, the __bridge_transfer is correct as the CFURLCreateStringByAddingPercentEscapes function returns a retained object (it has "create" in its name). You want ARC to take ownership of the returned object and insert a release (or autorelease in this case) to balance this out.

The __bridge cast for originalstring is correct too, you don't want ARC to do anything special about it.

Thank-you - this helped immensely. I just wanted to make sure that my understanding of the docs were correctly being applied.

CFBridgingRelease()
NSData *imageData = CFBridgingRelease(ABPersonCopyImageData(person))

objective c - Correct bridging for ARC? - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 43

As mentioned in the comments, I think it's fine to talk about ARC and the contents of Automatic Reference Counting here.

__autoreleasing is not meant to be used like that. It's used for passing indirect object references (NSError**, etc). See 4.3.4 Passing to an out parameter by writeback.

According to 3.2.4 Bridged casts, the __bridge_transfer is correct as the CFURLCreateStringByAddingPercentEscapes function returns a retained object (it has "create" in its name). You want ARC to take ownership of the returned object and insert a release (or autorelease in this case) to balance this out.

The __bridge cast for originalstring is correct too, you don't want ARC to do anything special about it.

Thank-you - this helped immensely. I just wanted to make sure that my understanding of the docs were correctly being applied.

CFBridgingRelease()
NSData *imageData = CFBridgingRelease(ABPersonCopyImageData(person))

objective c - Correct bridging for ARC? - Stack Overflow

objective-c automatic-ref-counting
Rectangle 27 45

Simply remove all calls to -release. You're not allowed to call -release under ARC because the compiler will insert all the necessary retain/release calls for you. Read more about ARC here.

The other way is to use the conversion tool, and Xcode can convert your project to ARC (including removing these calls) for you:

However I'd recommend you start using ARC, it will make things a lot easier and actually faster too.

Is there any way to just disable ARC in the LLVM compiler? When I click Convert to Objective-C ARC... it says all targets already use it.

objective c - ARC error when compiling - Stack Overflow

objective-c ios automatic-ref-counting
Rectangle 27 45

Simply remove all calls to -release. You're not allowed to call -release under ARC because the compiler will insert all the necessary retain/release calls for you. Read more about ARC here.

The other way is to use the conversion tool, and Xcode can convert your project to ARC (including removing these calls) for you:

However I'd recommend you start using ARC, it will make things a lot easier and actually faster too.

Is there any way to just disable ARC in the LLVM compiler? When I click Convert to Objective-C ARC... it says all targets already use it.

objective c - ARC error when compiling - Stack Overflow

objective-c ios automatic-ref-counting
Rectangle 27 45

Simply remove all calls to -release. You're not allowed to call -release under ARC because the compiler will insert all the necessary retain/release calls for you. Read more about ARC here.

The other way is to use the conversion tool, and Xcode can convert your project to ARC (including removing these calls) for you:

However I'd recommend you start using ARC, it will make things a lot easier and actually faster too.

Is there any way to just disable ARC in the LLVM compiler? When I click Convert to Objective-C ARC... it says all targets already use it.

objective c - ARC error when compiling - Stack Overflow

objective-c ios automatic-ref-counting
Rectangle 27 45

Simply remove all calls to -release. You're not allowed to call -release under ARC because the compiler will insert all the necessary retain/release calls for you. Read more about ARC here.

The other way is to use the conversion tool, and Xcode can convert your project to ARC (including removing these calls) for you:

However I'd recommend you start using ARC, it will make things a lot easier and actually faster too.

Is there any way to just disable ARC in the LLVM compiler? When I click Convert to Objective-C ARC... it says all targets already use it.

objective c - ARC error when compiling - Stack Overflow

objective-c ios automatic-ref-counting
Rectangle 27 38

It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is that zeroing weak references are only available in Mac OS X 10.7 and iOS 5. While the rest of ARC was backported to 10.6 and iOS 4, weak references cannot be used at all on these OS's.

Thanks for that @cobbal. At least in XCode 4.2 beta, you CANNOT use weak in a property declaration if your deployment target is < iOS 5: you must use assign. Message is error: the current deployment target does not support automated __weak references

Thank you @Yar, I was getting that error and did not know where it came from!

@MarkAdams it does, but as the name implies they are unsafe. When the object a weak references points to is destroyed, the weak reference goes to nil. With unsafe_unretained references, however, the reference points to the same (now deallocated) chunk of memory, and any messages sent to it will likely result in a segfault.

Further note: Mac OS X 10.6 support is limited to 64-bit apps; 32-bit code uses the legacy runtime and cant use ARC at all.

objective c - Zeroing Weak References in ARC - Stack Overflow

objective-c clang automatic-ref-counting
Rectangle 27 38

It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is that zeroing weak references are only available in Mac OS X 10.7 and iOS 5. While the rest of ARC was backported to 10.6 and iOS 4, weak references cannot be used at all on these OS's.

Thanks for that @cobbal. At least in XCode 4.2 beta, you CANNOT use weak in a property declaration if your deployment target is < iOS 5: you must use assign. Message is error: the current deployment target does not support automated __weak references

Thank you @Yar, I was getting that error and did not know where it came from!

@MarkAdams it does, but as the name implies they are unsafe. When the object a weak references points to is destroyed, the weak reference goes to nil. With unsafe_unretained references, however, the reference points to the same (now deallocated) chunk of memory, and any messages sent to it will likely result in a segfault.

Further note: Mac OS X 10.6 support is limited to 64-bit apps; 32-bit code uses the legacy runtime and cant use ARC at all.

objective c - Zeroing Weak References in ARC - Stack Overflow

objective-c clang automatic-ref-counting
Rectangle 27 38

It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is that zeroing weak references are only available in Mac OS X 10.7 and iOS 5. While the rest of ARC was backported to 10.6 and iOS 4, weak references cannot be used at all on these OS's.

Thanks for that @cobbal. At least in XCode 4.2 beta, you CANNOT use weak in a property declaration if your deployment target is < iOS 5: you must use assign. Message is error: the current deployment target does not support automated __weak references

Thank you @Yar, I was getting that error and did not know where it came from!

@MarkAdams it does, but as the name implies they are unsafe. When the object a weak references points to is destroyed, the weak reference goes to nil. With unsafe_unretained references, however, the reference points to the same (now deallocated) chunk of memory, and any messages sent to it will likely result in a segfault.

Further note: Mac OS X 10.6 support is limited to 64-bit apps; 32-bit code uses the legacy runtime and cant use ARC at all.

objective c - Zeroing Weak References in ARC - Stack Overflow

objective-c clang automatic-ref-counting
Rectangle 27 38

It's mostly right, but assign properties are still treated the same as they ever were, only weak ones are zeroing. Another caveat is that zeroing weak references are only available in Mac OS X 10.7 and iOS 5. While the rest of ARC was backported to 10.6 and iOS 4, weak references cannot be used at all on these OS's.

Thanks for that @cobbal. At least in XCode 4.2 beta, you CANNOT use weak in a property declaration if your deployment target is < iOS 5: you must use assign. Message is error: the current deployment target does not support automated __weak references

Thank you @Yar, I was getting that error and did not know where it came from!

@MarkAdams it does, but as the name implies they are unsafe. When the object a weak references points to is destroyed, the weak reference goes to nil. With unsafe_unretained references, however, the reference points to the same (now deallocated) chunk of memory, and any messages sent to it will likely result in a segfault.

Further note: Mac OS X 10.6 support is limited to 64-bit apps; 32-bit code uses the legacy runtime and cant use ARC at all.

objective c - Zeroing Weak References in ARC - Stack Overflow

objective-c clang automatic-ref-counting