Trouble with property (copy) and retain counts
Trouble with property (copy) and retain counts
- Subject: Trouble with property (copy) and retain counts
- From: Malayil George <email@hidden>
- Date: Tue, 5 May 2009 00:34:06 -0400
Hi, I'm a little confused with retain counts and properties. I would
appreciate some help in understanding this. I have a class setup as follows
@interface Cell : NSObject {
NSImage *image;
}
@property (copy) NSImage *image;
@end
Now, in my code, I do the following
NSImage *img = [[NSImage alloc] init];
Cell *cell = [[Cell alloc] init];
[cell setImage:img];
NSLog(@"Original image pointer: %x, retain count: %d", img,[img retainCount
]);
NSLog(@"Cell image pointer: %x, retain count: %d", cell.image, [cell.image
retainCount]);
NSLog(@"Cell image pointer: %x, retain count: %d", [cell image], [[cell
image] retainCount]);
It looks like everytime I call [cell image] the retain count goes up. Why
would this be the case? It doesn't matter if I set the property to copy or
retain, I see the same results. Am I expected to do the following
NSImage *img = [cell image];
NSLog(@"Cell image pointer: %x, retain count: %d", [image retainCount]);
I guess my question is do getters automatically increment the retain count
instead of my having to do [[cell image] retain]? Thanks
Regards
George M.P.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden