單例模式不適合使用繼承實(shí)現(xiàn)的原因
static id _instance;在整個(gè)內(nèi)存中只有一份,所以會(huì)導(dǎo)致一下錯(cuò)誤,用代碼說(shuō)明一下
- // 著名的雙鎖技術(shù)
{
If (_instance == nil)
{
@synchronized(self)
{
If(_instance == nil)
{
_instance = [super allocWithZone:zone];
}
}
}
return _instance;
}