Instruments란?
Xcode의 Instruments는 앱 성능을 분석하고, 메모리 누수 및 CPU 사용량을 최적화하는 데 도움을 주는 도구
Instruments에서 메모리 누수 탐지
Xcode에서 Product -> Profile 선택(
Cmd + I) 후 Instruments 실행Leaks 도구를 선택하여 메모리 누수 분석
Allocations 도구를 활용하여 객체 할당 및 해제 확인
Zombie Objects를 통해 해제된 객체 접근 여부 검사
메모리 누수 해결 방법
ARC(Automatic Reference Counting) 이해
Strong Reference Cycle 방지 (
waek또는unowned사용)메모리 프로파일링을 통한 실시간 디버깅
class Person {
var name: String
weak var friend: Person? // strong 참조 방지
init(name: String) {
self.name = name
}
}