UIImage imageNamed and release responsibility...?
I'm new to objective-c and to iphone development. I'm going through the samples and I've run across something confusing and seemingly in contradiction to the Cocoa Object Ownership Policy. Maybe I'm just missing something though. A sample project called MoveMe in the "iPhone Dev Center sample code" library has the code in question.
MoveMe has a UIView subclass called PlacardView. This view needs to make use of an image in the nib. It gets a reference to that image by invoking [UIImage imageNamed:]. Here is the confusing bit. It never calls retain on the returned image, but it does release it in PlacardView's dealloc. Cocoa's object ownership policy make me believe the sample should have retained this object if it was going to release it in the future. Is this release an error, or do they know something I don't?
Thanks in advance for any help.
Side note:
Even more confusing is the fact that it the view assigns the image DIRECTLY to one of its declared (retain) properties, circumventing the retain which would have been implicitly called if it invoked "self.property =".
Also, I did inspect the object at runtime and it does have a retainCount of 1 when returned from imageNamed, but I'd expect that to be the case since UIImage has the responsibility for maintaining its own cache...?
MoveMe has a UIView subclass called PlacardView. This view needs to make use of an image in the nib. It gets a reference to that image by invoking [UIImage imageNamed:]. Here is the confusing bit. It never calls retain on the returned image, but it does release it in PlacardView's dealloc. Cocoa's object ownership policy make me believe the sample should have retained this object if it was going to release it in the future. Is this release an error, or do they know something I don't?
Thanks in advance for any help.
Side note:
Even more confusing is the fact that it the view assigns the image DIRECTLY to one of its declared (retain) properties, circumventing the retain which would have been implicitly called if it invoked "self.property =".
Also, I did inspect the object at runtime and it does have a retainCount of 1 when returned from imageNamed, but I'd expect that to be the case since UIImage has the responsibility for maintaining its own cache...?
iPhone OS 3.0