Objective C memory management question with NSArray
- by Robert
I am loading an array with floats like this:
NSArray *arr= [NSArray arrayWithObjects:
[NSNumber numberWithFloat:1.9],
[NSNumber numberWithFloat:1.7],
[NSNumber numberWithFloat:1.6],
[NSNumber numberWithFloat:1.9],nil];
Now I know this is the correct way of doing it, however I am confused by the retail counts.
Each Object is created by the [NSNumber numberWithFloat:] method. This gives the object a retain count of 1 dosnt it? - otherwise the object would be reclaimed
The arrayWithObjects: method sends a retain message to each object.
This means each object has a retain cont of 2. When the array is de-allocated each object is released leaving them with a retain count of 1.
What have I missed?