Re: Setting pointer to nil
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