0

As far as I know, creating an NSMutableArray with a helper method such as arrayWithArray adds both the array and the mutable array to the current autorelease pool. With mutableCopy, the array being copied as added to the autorelease pool but the resulting NSMutableArray does not. Without ARC, it's a notable difference.

But when using ARC, is there any difference beyond what is described above and which is irrelevant with ARC? I've seen code using both ways. Is there an established best practice on how to create mutable versions of immutable objects, when ARC is turned on, and why is it so?

p4sh4
  • 3,292
  • 1
  • 20
  • 33
  • unless you have performance problem, don't worry about it. and without profiling, you can't tell which method is better. – Bryan Chen Jul 01 '14 at 23:25

1 Answers1

1

Since arrayWitharray add two object in current autorelease pool, but latter does not. So that performance of first one is slightly less due to the draining of autorelease pool. So use the latter one below. The simple and best way to convert immutable array to mutable array in arc or non arc:-

  NSMutableArray *array=[yourArray 
  mutableCopy];
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56