static RootViewController *sharedRootController = nil;
+(RootViewController *) sharedController{ @synchronized(self){
if (sharedRootController == nil) {
sharedRootController = [[[self alloc] init] autorelease];
}
}
return singleController;
}+(id) allocWithZone:(NSZone *)zone{
@synchronized(self){
if (sharedRootController == nil) {
sharedRootController = [super allocWithZone:zone];
return sharedRootController;
}
}
return nil;
}1. synchronized 这个主要是考虑多线程的程序,这个指令可以将{ } 内的代码限制在一个线程执行,如果某个线程没有执行完,其他的线程如果需要执行就得等着。
2、 allocWithZone 这个是重载的,因为这个是从制定的单例。所以返回 nil
3、 关于autorelease , iOS 上的程序,对于创建用于函数返回值的,都应该考虑 autorelease