Skip navigation.
 
mlRe: Intercepting retain/release of object
FROM : Jack Repenning
DATE : Mon Mar 24 05:31:12 2008

On Mar 21, 2008, at 2:36 PM, Sherm Pendley wrote:
> In short, the fact that you need a means to track down your -retain 
> and
> -release calls is indicative of a deeper problem. Examining the 
> retain count
> will not only fail to solve that problem, but will also obfuscate 
> the issue
> even further. You'd be far better off asking yourself why your -
> retains and
> -releases are so scattered that they're difficult to find and verify 
> in the
> first place - that's the *real* problem, not whatever arbitrary 
> value you
> happen to get back from -retainCount.


There are really two bits of advice, here, and they're separable.

The first is: you'll never make any sense out of retainCount.  Might 
as well just take that one to the bank.  Forget retainCount.  There's 
way too much stuff going on that you can't see in the code, you'll 
never make sense of it all.  That's the easy part.

The second is: it's best form to handle your retain/release stuff in 
the simplest, most on-sight verifiable way you possibly can.  If you 
find yourself wondering where an extra or missing retain or release 
is, then your best conclusion is that your retain/release code is too 
confusing.  Doing it in the accessors is the simplest, most at-a-
glance policy, and it covers most use.  In fact, Obj-C 2.0 provides 
you with a handy short hand to do it exactly this way, 
@property(retain).  Breaking in reatain and release (and maybe 
autorelease) can tell you things that make sense (unlike retainCount), 
but if you have to do that, your code's too complicated -- you'll have 
to do it again and again, every time you make changes.  Save yourself 
the trouble.  Simplify.

-==-
Jack Repenning
Chief Technology Officer
CollabNet, Inc.
8000 Marina Boulevard, Suite 600
Brisbane, California 94005
office: +1 650.228.2562
mobile: +1 408.835.8090
raindance: +1 877.326.2337, x844.7461
aim: jackrepenning
skype: jrepenning

Related mailsAuthorDate
mlIntercepting retain/release of object Stuart Malin Mar 19, 18:54
mlRe: Intercepting retain/release of object Jonathan del Strot… Mar 19, 19:04
mlRe: Intercepting retain/release of object Nick Zitzmann Mar 19, 19:04
mlRe: Intercepting retain/release of object Pierre Molinaro Mar 19, 19:09
mlRe: Intercepting retain/release of object Rob Napier Mar 19, 19:12
mlRe: Intercepting retain/release of object Stuart Malin Mar 19, 19:41
mlRe: Intercepting retain/release of object Scott Ribe Mar 21, 19:13
mlRe: Intercepting retain/release of object j o a r Mar 21, 20:38
mlRe: Intercepting retain/release of object Sherm Pendley Mar 21, 21:16
mlRe: Intercepting retain/release of object Stuart Malin Mar 21, 21:32
mlRe: Intercepting retain/release of object Sherm Pendley Mar 21, 22:36
mlRe: Intercepting retain/release of object Erik Buck Mar 21, 23:38
mlRe: Intercepting retain/release of object Jack Repenning Mar 24, 05:31
mlRe: Intercepting retain/release of object Stuart Malin Mar 24, 05:50
mlRe: Intercepting retain/release of object Jack Repenning Mar 24, 17:12