Some objects in Cocoa you have to add to autorelease pools and others are added by a Foundation method. Take for instance, these NSNumber messages:
I don't have to release the instance pointed to by myInt, when myInt is assigned to point the an instance the following way:
Do I have to release an NSNumber instance if I allocate it this way, since I do use alloc?:
On page 318, second paragraph of Kochan's book Programming in Objective-C it states:
What does this mean that it is owned by the method that returns it? And, how is it added to the autorelease pool without an explicit message which would do so?
I don't have to release the instance pointed to by myInt, when myInt is assigned to point the an instance the following way:
Code:
id myInt = [NSNumber numberWithInt:100];
Do I have to release an NSNumber instance if I allocate it this way, since I do use alloc?:
Code:
id myInt = [[NSNumber alloc] initWithInt:100];
On page 318, second paragraph of Kochan's book Programming in Objective-C it states:
In general, you don't need to worry about releasing an object returned by a Foundation method. Sometimes the object is owned by the method that returns it. Other times, the object is newly created and added to the autorelease pool by the method.
What does this mean that it is owned by the method that returns it? And, how is it added to the autorelease pool without an explicit message which would do so?