1
dinpatch_once_t 및 _sharedObject가 sharedInstance를 반복적으로 호출 할 때 0 및 nil로 설정되지 않은 이유를 이해하려고합니다. 그것은 코딩 된 방식으로, 정적 변수를 재설정 할 수 있기 때문에 로컬 변수가 다시 초기화되는 것 같습니다. ARC 또는 iOS 메모리 관리의 기본 기능은 무엇입니까?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;
}