• 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
Alloc Mocks my World
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Alloc Mocks my World


  • Subject: Alloc Mocks my World
  • From: Philip Dow <email@hidden>
  • Date: Thu, 25 Aug 2005 10:43:26 +0200

I thought I had my head wrapped around alloc, but apparently not. As far as I understand alloc, it produces an object with a retain count of 1. If I create an object with the standard MyObject *newObject = [[myobject alloc] init] the object will have a retain count of 1.

I am allocating and initializing an object like so:

JRLREntryCell *newCell = [[JRLREntryCell alloc] initWithEntry: [[browseArrayController selectedObjects] objectAtIndex:0]];

The very next line of code reads: int retCount = [newCell retainCount]; And what is the retain count? 3. Three! Not one. Not even two. Three. How in the world is my allocation and initialization producing a retain count of three?

The initialization is simple. I need the object to become the owner of a nib file. I also need it to keep a week reference to the entry I'm passing in via the initWithEntry: portion. So...

- (id) initWithEntry:(JournlerEntry*)representedEntry {
    if ( self = [super init] ) {
        entry = representedEntry;
        [NSBundle loadNibNamed:@"EntryCell" owner:self];
    }
    return self;
}

Once the nib loads, I pass the weakly referenced entry to a custom view in the nib file:

- (void) awakeFromNib {
    [headerView setDisplayedEntry:entry];
}

Nothing I've read about object allocation and nib ownership suggests that this code would produce an object with a retain count of three. If declaring the object owner of the nib increased the retain count, then maybe I would understand two. But in all the examples of seen, no one seems to worry that something like this is happening. The "Loading Resources" documentation doesn't mention this either. Does anyone know how the retain count hits 3 then?

-Phil

http://phildow.net
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Alloc Mocks my World
      • From: j o a r <email@hidden>
References: 
 >Re: refreshObject:mergeChanges: vs. stale transient (From: Frank Illenberger <email@hidden>)

  • Prev by Date: Re: Printing an NSOpenGLView
  • Next by Date: Re: Alloc Mocks my World
  • Previous by thread: Re: Superscript causing crash
  • Next by thread: Re: Alloc Mocks my World
  • Index(es):
    • Date
    • Thread