I am new to the iPhone / Mac space and this is probably a pretty basic question, I have done some searching and have not found the direct answer.
I would like to know if the addObject method for Arrays / Mutable Arrays does a shallow (pointer only) or deep (copies object) when adding.
- A mutable array that has been alloc
- A NSString that has been alloc with some sort of init
- We addObject the string to the mutable array
- We then release the NSString
If this is the proper way to do things, that it is assumed that the addObject will do a deep copy of the NSString. Just confirming that this is the proper way to do memory management with mutable array …
addObject:does a shallow copy. What you’re missing is thatNSMutableArrayretains the object, so it does not go away, but does not require a deep copy. This is a key point to Objective-C memory management. You should read the Memory Management Programming Guide. Cocoa memory management is not complicated, and is incredibly consistent. I have a shortened summary at Three Magic Words.