컴&프로그래밍/Etc, Install
NSAutorealsePool과 automic reference counting mode
eunguru
2011. 12. 14. 10:25
Xcode4를 설치후 첫 예제를 실행하기 위해 책에 있는 아래와 같은 코드를 작성하였다.
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"Hello World!");
[pool drain];
return 0;
}
예제는 매우 단순하다. Hello world를 출력하는 것 뿐. ...
그러나..아래 코드를 작성하고 나면 issue navigator 에 issue 가 발생되는것을 볼수 있다.
issue는 NSAutorealsePool is unavailable. not available in automatic reference counting mode.
로 출력된다.
Xcode로 프로그래밍을 막 시작한 초보자에게는 매우 당황스러운 문제가 발생했다.
automatic reference counting mode 는 또 뭘까..
책을 뒤졌지만 설명이 없다....
모드라는 말에 생성한 프로젝트에 타겟 셋팅을 찾아보기로 했다.
그리고.. 아래와 같은 셋팅을 발견했다.
그림에 objective-c automatic reference counting 항목에 Yes 라고 되어 있는것을 볼수 있다.
이 프로젝트는 자동으로 레퍼런스 카운팅을 유지한다는 뜻이다.
기본적으로는 Yes 로 되어 있어 할당/삭제를 사용자가 하지 않아도 관리되도록 한다는것 같다.
암튼 예제의 NSAutorealsePool을 사용하기에는 해당 셋팅을 No 로 변경해줘야한다.
아니면 셋팅을 변경하지 않고 다음과 같이 소스를 변경할 수 있다.
#import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { @autoreleasepool { NSLog(@"Hello World!"); } return 0; }