What are the pros and cons of creating an array (or any other collection using its respective factory method) with
[[NSArray alloc] init]
vs
[NSArray array]
in objective C? It seems like the latter factory method allows us to not worry about memory management, so I was curious if there’s any point in ever using alloc + init, though I’m now more interested in all the differences between these two, and why one would choose one over the other.
Prior to ARC there was a critical difference. The
alloc/initcase returned a retained object, while thearraycase returned an autoreleased object.With ARC the difference is less important. Probably the first case is a hair more efficient, but in most scenarios they are interchangeable.