Re: Trouble with property (copy) and retain counts
Re: Trouble with property (copy) and retain counts
- Subject: Re: Trouble with property (copy) and retain counts
- From: Jean-Daniel Dupas <email@hidden>
- Date: Tue, 5 May 2009 14:36:21 +0200
If the retain count confuses you, you stop to using it as it's almost
never relevant.
That said, have a look at the atomic section in the property references:
http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocProperties.html
Le 5 mai 09 à 06:34, Malayil George a écrit :
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
_______________________________________________
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