프로그래밍/iOS
[iOS] ARC 적용 후, 메모리 해제 방식 비교
김잉장
2016. 11. 30. 15:22
개요
- 이제 ARC(Auto Reference Counting) 옵션을 통해, 메모리를 자동으로 해제할 수 있게 되었다.
- 기존 방식은 MRC(Manual Reference Counting)라고 한다.
설정 방법
- Build Setting -> Objective-C Automatic Reference Counting을 YES로 설정하면 기능이 활성화 된다.
autoreleasepool vs ARC
- autoreleasepool 내부에서 사용된 메모리들은 autoreleasepool가 끝나는 시점에서 해제된다.
- arc의 경우 자동으로 해제된다.
autoreleasepool 방식
#if !__has_feature(objc_arc)
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// Code
[pool release];
#endif
ARC 적용
@autoreleasepool {
// Code
}