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

Re: Alloc Mocks my World


  • Subject: Re: Alloc Mocks my World
  • From: David Hoerl <email@hidden>
  • Date: Thu, 25 Aug 2005 10:47:39 -0400


...

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?


...
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


Phil,

A technique I have used with great success is to wrap the calls inside your own auto release pool, then release it (use this for debugging only!)

For example, try this (I didn't):


NSAutoRelease *myPool = [NSAutoRelease new]; JRLREntryCell *newCell = [[JRLREntryCell alloc] initWithEntry: ...]; [pool drain];

NSLog(@"Retaincount %d", [newCell retainCount];

This technique is handy for verifying assumptions about complex relationships.

David

_______________________________________________
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: John Stiles <email@hidden>
  • Prev by Date: Custom Title bars
  • Next by Date: Re: Printing an NSOpenGLView
  • Previous by thread: Re: Custom Title bars
  • Next by thread: Re: Alloc Mocks my World
  • Index(es):
    • Date
    • Thread