3

A variable created with the [NSArray array] method isn't completely dealloc when the controller dealloc

2

5 Answers 5

3

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

https://stackoverflow.com/a/5423319/5019395

Comments

0

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.

Comments

0

[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/

Comments

-1

[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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.