Saran
Saran

Reputation: 6392

After building nsmutablearray should i convert it to nsarray for performance benefit?

Wondering, After building nsmutablearray should i convert it to nsarray for performance benefit? If i am going to keep and use that array for quite sometime.

Upvotes: 8

Views: 122

Answers (2)

trojanfoe
trojanfoe

Reputation: 122391

No. The conversion itself will cost time and CPU cycles and you won't gain anything from the conversion.

Upvotes: 5

Mick Walker
Mick Walker

Reputation: 3847

I would actually say it depends. If I create a NSMutableArray within a method and needs to return it, then generally unless the caller requires the ability to directly modify the array values, I will return the NSMutableArray as a NSArray for the sake of simlicity and to reduce the memory footprint of the application.

However, if I am creating the NSMutableArray for direct consumption within the current method, then I seen no benefit of casting it to a NSArray.

Upvotes: 0

Related Questions