If have an array of integers
array1 = {7,8,9};
and i add it to another array called 2darray.
If i release array1 will 2darray still have 7,8,9 values in it or will i have to do something like copy to copy array1 to 2darray and then safely release array1 and still have those values 7,8,9 in 2darray?
Okay, your question as written doesn’t make sense, so I’m going to make some assumptions and answer what you are hopefully looking for.
First of all, NSArray’s can only contain objects, and not scalar values like int’s in your code. Let’s take a look at the following code instead:
When you add an object to an array, it automatically retains it, so in this case the array that array1 is pointing at is retained once by the pointer (array1) and then a second time by array2 (it has a retainCount of 2).
When you release it, it only removes ONE of the retains (the retainCount now becomes 1) so the object itself is never released and stays valid.
Keep in mind that this is a pretty common way of creating an array and adding it to a second place. You are “safely” releasing array1 and can set it to nil without affecting the object that is still in array2.