sharedInstanceを繰り返し呼び出したときに、dinpatch_once_tと_sharedObjectがそれぞれ0とnilに設定されない理由を理解しようとしています。これがコーディングされている方法では、静的な値をリセットできるため、ローカル変数が再初期化されるようですよね?ここで理解していないARCまたはiOSのメモリ管理の基本は何ですか?
+ (id)sharedInstance
{
// structure used to test whether the block has completed or not
static dispatch_once_t p = 0;
// initialize sharedObject as nil (first call only)
__strong static id _sharedObject = nil;
// executes a block object once and only once for the lifetime of an application
dispatch_once(&p, ^{
_sharedObject = [[self alloc] init];
});
// returns the same object each time
return _sharedObject;
}