• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Trouble with property (copy) and retain counts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Trouble with property (copy) and retain counts
      • From: Jean-Daniel Dupas <email@hidden>
  • Prev by Date: Printing an NSDocument
  • Next by Date: WebView loses script context
  • Previous by thread: Re: Printing an NSDocument
  • Next by thread: Re: Trouble with property (copy) and retain counts
  • Index(es):
    • Date
    • Thread