0
코드에서 객체를 생성 등록 obj가 외부에서 내부 @autoreleasepool 블록에 있지 오토 릴리즈 왜는 외부 @autoreleasepool 블록과 이상한 __weak 포인터 동작
For __autoreleasing objects, the new pointee is retained, autoreleased, and stored into the lvalue using primitive semantics.
?
번째 예 :
@autoreleasepool {
id __weak obj = nil;
@autoreleasepool {
id __strong obj1 = [[NSObject alloc] init];
obj = obj1;
NSLog(@"obj: %@", obj); // <NSObject: 0x7857657>
NSLog(@"obj retain count: %d", (int) _objc_rootRetainCount(obj1)); // 2
_objc_autoreleasePoolPrint();
}
NSLog(@"obj retain count: %d", (int) _objc_rootRetainCount(obj)); // 1
NSLog(@"obj: %@", obj); // (null)
_objc_autoreleasePoolPrint();
}
왜 NSLog 출력 "(널)"수를 보유하는 경우 1?
ok. 감사. 하지만 왜 (null)이 인쇄되고 있는지 대답을 얻지 못했습니다. – AndrewShmig
@AndrewShmig :'obj'가 null이기 때문에 ('nil') – newacct