Re: NSString Retain Count of 2147483647
Re: NSString Retain Count of 2147483647
- Subject: Re: NSString Retain Count of 2147483647
- From: Bill Bumgarner <email@hidden>
- Date: Wed, 24 Jun 2009 11:03:59 -0500
On Jun 24, 2009, at 10:45 AM, Martin Redington wrote:
Is that really always true?
Pretty much. The only time the result of -retainCount will be 100%
consistent and predictable is when the object being queried is an
instance of a subclass of NSObject where you created the subclass
*and* you never pass the object through any AppKit or Foundation APIs.
Break either of those rules and there *may* be cases where the retain
count doesn't make sense because something somewhere is caching a
reference, has dropped it into a pool, and/or done something else with
your object.
I.e. relying on retainCount work sometimes, but it is so terribly
misleading when it doesn't work that it isn't worth the risk.
I found that inspecting retainCount with caveman debugging, and
over-riding retain/release/dealloc very helpful in some specific
contexts, for example to catch bugs like
id someObject = [[MyObject alloc] init];
[someArray addObject:someObject];
[someObject release];
// Oops. someArray was nil, and now someObject is gone
The best way to find situations such as these is to use ObjectAlloc
within Instruments. It can track full life cycles of objects. If you
have access to the Snow Leopard seeds, I would suggest doing all your
development work there, even if targeting 10.5 as your deployment
platform. The analysis tools in Snow Leopard's development tools are
vastly superior to the Leopard version.
As for the above, the retain count really isn't useful. Or, more
precisely, the retain count is a rather roundabout way of deducing the
problem. So is -retain/-release.
If someArray really should never be nil in that case, use an assert or
other explicit test.
b.bum
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden