NSArray has a lot of extremely complicated and undocumented behaviour. It does some crazy stuff to improve real world performance.
The high level behaviour of NSArray
and NSMutableArray
is well documented but those two classes do not actually exist, instead you get instances of other classes, which class you actually get will depend on heuristic decisions the framework will make based on the actual data in the array and how you access it.
Creating copies of an array might not actually make a copy until you start modifying it. And even then, it may never make copies, it might keep the original array around and maintain a delta of changes that have been made.
If you need to know what is going on, then you should not be using NSArray
at all. Instead you should drop to C arrays or perhaps even NSMutableData
(tip: NSMutableData
is awesome when the contents are potentially too big to fit in RAM).
The specific behaviour you are seeing could change at any time depending on the operating system version and perhaps even the hardware your app is executing on. Do not rely on how NSArray
works in practice, because that is unpredictable. Instead rely on the documentation. Anything undocumented cannot be trusted, especially with NSArray
which is a special case class.
Also, never ever subclass NSArray
. Instead create a wrapper class that uses NSArray
internally.