2011-10-28 7 views
3

나는 GCD에 대한 기사를 읽고, 예를 들어이있다 :Autoreleasepool 및 dispatch_async

dispatch_queue_t bgQueue = myQueue; 
dispatch_async(dispatch_get_main_queue(), ^{ 
    NSString *stringValue = [[[textField stringValue] copy] autorelease]; 
    dispatch_async(bgQueue, ^{ 
     // use stringValue in the background now 
    }); 
}); 

전합니다 (autoreleasepool에 호출됩니다) 클릭 핸들러의 방법은, 내가 있기 때문에, stringValue을 손실 것을 배치하면 autoreleasepool은 클릭 이벤트 후 파괴됩니까?

답변

9

내부 블록? 아니오, 당신은 그 가치를 잃지 않을 것입니다. Objective-C 개체 변수 (__block로 선언되지 않은)가 블록 내에서 참조되고 블록이 복사되면 해당 개체가 자동으로 유지됩니다. 블록이 해제되면 해당 객체도 해제됩니다. dispatch_async()은 블록 복사 및 해제를 담당합니다.

+0

이제는 의미가 있습니다, 감사합니다. – INs