• 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: John Stiles <email@hidden>
  • Date: Thu, 25 Aug 2005 10:59:42 -0700

FWIW, I don't think you want to drain on an NSAutoreleasePool. (- drain was added for GC Cocoa and isn't really meant for app developers yet, IIRC.)
Use [pool release].
However, I would not rely on retain counts at all. There are just too many counterintuitive things about the raw retain count, including the autorelease count but also including object relationships that you may have no control over (and which may theoretically change from release to release of OS X). If you balance your retains and releases, things should work. Use ObjectAlloc to verify that they do. If you see a problem, your retains and releases probably aren't balanced after all ;) ;)
Honestly I think the world would be a better place for newbies if - retainCount was a private method. It seems like a good debugging tool but it's just not.


On Aug 25, 2005, at 7:47 AM, David Hoerl wrote:


...

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:
40blizzard.com


This email sent to email@hidden


_______________________________________________ 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: Finlay Dobbie <email@hidden>
References: 
 >Re: Alloc Mocks my World (From: David Hoerl <email@hidden>)

  • Prev by Date: Re: Need help in setting up an NSTevtView in an overlay window
  • Next by Date: InstantMessage Framework problem
  • Previous by thread: Re: Alloc Mocks my World
  • Next by thread: Re: Alloc Mocks my World
  • Index(es):
    • Date
    • Thread