• 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: Setting pointer to nil
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting pointer to nil


  • Subject: Re: Setting pointer to nil
  • From: John Stiles <email@hidden>
  • Date: Tue, 20 Dec 2005 15:11:11 -0800

On Dec 20, 2005, at 3:01 PM, Shaun Wexler wrote:

On Dec 20, 2005, at 2:50 PM, Ricky Sharp wrote:

- (void)setManagedObjectContext:(id)newManagedObjectContext
{
[newManagedObjectContext retain];
[managedObjectContext release];
managedObjectContext = newManagedObjectContext;
}

FWIW, it's usually better & safer to write setters like this:

- (void)setManagedObjectContext:(id)newManagedObjectContext
{
id oldManagedObjectContext = managedObjectContext;
managedObjectContext = [newManagedObjectContext retain];
[oldManagedObjectContext release];
}

Out of curiosity, why? I see that this fixes a race condition, in case you're writing multi-threaded code, but is there more to it than that?

_______________________________________________
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: Setting pointer to nil
      • From: Shawn Erickson <email@hidden>
References: 
 >Setting pointer to nil (From: Jeff LaMarche <email@hidden>)
 >Re: Setting pointer to nil (From: Ricky Sharp <email@hidden>)
 >Re: Setting pointer to nil (From: Shaun Wexler <email@hidden>)

  • Prev by Date: Cocoa multithreading in C (terrible idea, isn't it?)
  • Next by Date: Re: Cocoa multithreading in C (terrible idea, isn't it?)
  • Previous by thread: Re: Setting pointer to nil
  • Next by thread: Re: Setting pointer to nil
  • Index(es):
    • Date
    • Thread