On Nov 21, 2008, at 5:21 PM, Ricky Sharp wrote:
But, that's only if dealloc releases objects directly and doesn't use accessors or use the workaround shown below.

Yes, although following "best practice" is assumed...  :-)

I'm now really curious as to why UIViewController uses an accessor in dealloc since that's supposed to be bad practice. Has a bug been filed against that too?

Yes.

The remedy is to ensure that outlet variables are also set to nil in dealloc:

- (void)dealloc {
  // release outlets and set variables to nil
  [anOutlet release], anOutlet = nil;
  [super release];
}
That is indeed a workaround, but one of the reasons I moved towards using accessors instead (i.e. I didn't have to think about all the edge cases where clearing out the ivar was absolutely necessary; the accessor always does the right thing).

I would suggest that releasing then setting the variable to nil is a better strategy than using the accessor.

Now then, two things...
(1) In my personal code, I'm the only developer and do not integrate with any third party code (I only use Apple's SDKs directly). Having said that, I do have full control over my own objects and thus don't have any pitfalls in using accessors in inits and/or deallocs.


That's fine; if you're *sure* you'll never run into a problem such as this...

(2) But, I can see where in the general case, this is becoming quite problematic for folks. After all, it's always dangerous to base your code on implementation details such as these.

... indeed, this is why best practice is given as such.

mmalc



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to