Re: Is Apple's singleton sample code correct?
Re: Is Apple's singleton sample code correct?
- Subject: Re: Is Apple's singleton sample code correct?
- From: Uli Kusterer <email@hidden>
- Date: Sat, 26 Nov 2005 18:43:33 +0100
Am 26.11.2005 um 18:21 schrieb David Gimeno Gost:
+ (MyGizmoClass*) sharedInstance
{
@synchronized( self ) {
if ( sharedGizmoManager == nil ) {
// The extra -retain in +allocWithZone: is needed only
when the
// result of [[alloc] init] is assigned to a variable
other than
// our static shared instance, so we undo it here.
sharedGizmoManager = [[[self alloc] init] release];
}
}
return sharedGizmoManager;
}
Weren't we trying to make our code safer and more readable? I hope
I never end up writing code like
[[[self alloc] init] release]
in any of my programs. This code effectively does nothing, and its
side effects do everything. Yes, the comment elaborates on that, but
in this case I'd prefer self-documenting code.
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
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