A variable created with the [NSArray array] method isn't completely dealloc when the controller dealloc
-
How do you know that? – trojanfoe Nov 17 '15 at 10:12
-
Difference between NSArray.array/.new /@\[\]/alloc-init](http://stackoverflow.com/questions/33297171/difference-between-nsarray-array-new-alloc-init – Kirit Modi Nov 17 '15 at 10:19
5 Answers
Under ARC.
[NSArray array]
and [[NSArray alloc] init]
do the same. Return an immutable, empty array. ARC takes care of the memory management.
No ARC.
[NSArray array]
returns an array which will be autoreleased.
[[NSArray alloc] init]
returns an array that you have to take care of in terms of memory management by calling a release
on it when you don't need it anymore.
Note
There is little use of instantiating empty immutable array. Check NSArray's
other initializers that take items as arguments. In this case, you have an immutable array with items in it. But again, it all depends on your needs.

- 1
- 1

- 39,540
- 23
- 113
- 143
The [NSArray Array] class method by itself produces an autoreleased array, meaning you don't have to (and should not) release
it manually.
[NSArray Array] is a constructor vending.
But after coming to ARC(Automatic reference counting) there is no such thing as release
. So the difference between alloc-init
and a constructor vending an autoreleased
object becomes practically irrelevance.
The array
is a class method by itself produces an autoreleased array, which means you don't have to (and should not) release it manually. Since iOS 5 with ARC, you don't have to worry about deallocating processing.

- 1,638
- 14
- 26
[NSArray array] this types of method in objective c called as convenience method which returns objects which we don't own, they are autorelease objects. But if you want ownership of object in that case you have to use alloc init methods to create any object/

- 1,581
- 9
- 16
[NSArray Array] doesn't even compile. You probably mean [NSArray array].
[NSArray array] is a convenience constructor which returns an autoreleased object. There are many convenience constructors in Cocoa and in people's own code.
The rest of your question frankly doesn't make sense.

- 51,477
- 5
- 75
- 98