1

With NSMutableArray we get additional methods like

  • addObject
  • insertObject
  • removeObjectAtIndex

Why we want to use non-mutable NSArray when we get additional methods in NSMutableArray? Is there any performance penalty when using NSMutableArray over NSArray?

2
  • 1
    Memory is quite a good reason. Block any attempts of modification is a good one too. Commented May 23, 2015 at 10:53
  • Why would you use a mutable array for things like storing the letters of the alphabet? Or something like that? Commented May 23, 2015 at 10:58

1 Answer 1

0

Just check this link:

It is mentioned in the above link, just portraying in my words:

While calling an API that wants to copy the array and if you send -copy to an immutable array(NSArray), it just bumps the retain count, but while sending -copy to a mutable array(NSMutableArray) will allocate heap memory. So bumping the retain count is much faster than allocating heap memory.

Here comes the performance issue.

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

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.