• 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: Simple dealloc question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple dealloc question


  • Subject: Re: Simple dealloc question
  • From: Milo Bird <email@hidden>
  • Date: Mon, 15 Oct 2007 10:50:49 +0100

That's correct but only for this object. Application can be trying to send messages to this object forever. And setting nil will help to track it down.

I'm sorry, I don't follow this argument... What do you mean, "application can be trying to send messages to this object forever"?


In my opinion, setting instance variables to nil in dealloc is a cautious step too far. Any messages sent to the object in error after dealloc could end up anywhere. What does it matter if the instance variables point to released objects, when the receiver is itself a released object?

I have one more question. In the same code there is

// Standard accessors
- (Track *)track
{
    return [[track retain] autorelease];
}


Why not just // Standard accessors - (Track *)track { return track; }

Consider the following snippet:

Track *track = [someObject track];
[someObject setTrack:[[[Track alloc] init] autorelease]]; // Assuming there is a setter!
NSLog(@"%@", track); // track has been released, unless the accessor retained or copied the return value...


If your object is mutable and the accessor simply returns the instance variable, it may get released inadvertently before the caller is finished with it. Retaining and then autoreleasing avoids this problem.

Note that neither convention is necessarily wrong. Apple tends to use the latter form in their own classes, despite the fact that it's less safe.

Milo

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Simple dealloc question
      • From: Ricky Sharp <email@hidden>
    • Re: Simple dealloc question
      • From: Andreas Mayer <email@hidden>
References: 
 >Simple dealloc question (From: Bob Ueland <email@hidden>)
 >Re: Simple dealloc question (From: Robert Cerny <email@hidden>)
 >Re: Simple dealloc question (From: Milo Bird <email@hidden>)
 >Re: Simple dealloc question (From: Robert Cerny <email@hidden>)

  • Prev by Date: Re: Simple dealloc question
  • Next by Date: Re: Simple dealloc question
  • Previous by thread: Re: Simple dealloc question
  • Next by thread: Re: Simple dealloc question
  • Index(es):
    • Date
    • Thread