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 (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/devlists%40shadowlab.org
This email sent to devli...@shadowlab.org
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to arch...@mail-archive.com