Objective C memory management question with NSArray
Posted
by
Robert
on Stack Overflow
See other posts from Stack Overflow
or by Robert
Published on 2010-12-31T13:38:27Z
Indexed on
2010/12/31
13:54 UTC
Read the original article
Hit count: 165
objective-c
|memory-management
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 reclaimedThe
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?
© Stack Overflow or respective owner