On page 326 in the book Programming in Objective-C 2.0 the author says:
myNumber = [[NSNumber alloc] initWithInt: 1000];
Of course, based on previous discussions, if you create
myNumberthis way, you are re- sponsible for subsequently releasing it when you’re done using it with a statement such as follows:
[myNumber release];
My question is:
Does this mean that if I create an NSNumber object with this statement
NSNumber *myNumber = [NSNumber numberWithInteger: 100];
I don’t have to release the object myNumber myself?
This link is your bible
In the case of
[NSNumber numberWithInt:]it returns an autoreleased object, and you don’t need to do anything to release it properly. Unless youretainit, of course, in which case you would callreleaseon it, likely from yourdeallocmethod.[[NSNumber alloc] initWithInt:]returns an object with a retain count of one (from callingalloc). You are responsible for releasing any object created this way.