To understand this, you need to understand the number of links. In Objective-C, each object has a reference count (i.e., the number of strong references to the object). If there are no strong links, the reference count is 0 , and the object will be freed.
self.a = @[@1, @2]; creates an auto-implemented NSArray (meaning that it will be released automatically at a later stage) and sets the value to self.a After autoreleasepool is exhausted, the reference count of this array is 0 (in the absence of other strong links), and it is freed. self.a , which is a weak variable, is automatically set to nil.
If you use [[NSArray alloc] init] to initialize your array and assign it to a weak pointer, the object will be released immediately after the assignment. In NSLog , a will be nil .
__weak NSArray* a = [[NSArray alloc] initWithObjects:@"foo", @"bar", nil]; NSLog(@"%@", a);
In Xcode 4.6, the compiler will warn you of the latter case.
source share