SlideShare a Scribd company logo
1 of 12
Auto Reference Counting
          (ARC)




         김정문




                          1
ARC 소개




   1. ARC는 Xcode 4.2, iOS4, iOS5에서 사용가능
         (단, iOS4에서는 Weak 지원하지 않음)
   2. 컴파일 시에 자동으로 적절한 위치에 retain, release, autorelease와
      같은 메모리 관리와 관련된 메소드를 추가 함.
   3. 가비지 컬렉터와 유사한 기능을 제공하지만 가비지 컬렉터는 아님




                                                          2
새로운 Rule




     1.    retain, release, retainCount, autorelease 사용 불가능

     2.    @selector(retain), @selector(release) 사용 불가능

     3.    Dealloc 메소드에서 [super dealloc] 호출 X

     4.    id와 void* 같은 암시적 형 변환 불가능

     5.    NSAutorelease 사용 불가능 @autoreleasepool{} 사용




                                                              3
새로운 Rule




   1. strong : 기본 값(묵시적)

   2. weak : zeroing weak reference. 해제되면 nil이 된다.

   3. unsafe_unretained : weak reference. 대상 객체가 해제되면 댕글링
       포인터(dangling pointer)가 된다.
   4. autoreleasing : id * 형식의 인수가 리턴 시 자동적으로 해제되도록
       지정된다.




                                                            4
Strong Reference




                    Strong Reference

     1. strong 키워드는 retain과 비슷하다.
     2. 해당 클래스가 소유하는 멤버변수
     3. 해당 클래스의 오브젝트가 메모리에서 해제되지 않는 한 해당 오브젝트의
        strong 멤버는 절대로 메모리 상에서 해제되지 않는다.
     4. IB에서 File’s Owner와 nil 파일의 최상위 객체들은 strong




                                                     5
Strong Reference




    (__strong) NSString *firstName = self.textField.text;




                                                            6
Strong Reference




                   7
Strong Reference




                   8
Strong Reference




                   9
Weak Reference




                   Weak Reference


     1. weak의 경우는 assign 과 비슷하면서도 다르다.
     2. weak가 붙은 property는 해당 메모리가 해제되면 자동으로 nil로 초기화 된
        다.
     3. 인터페이스 빌더에서 연결된 IBOutlet 등에서 주로 사용
     4. strong과 반대로 weak는 해당 클래스의 소유가 아님.




                                                          10
Weak Reference




          __weak NSString *weakName = self.textField.text;




                                                             11
Weak Reference




                 12

More Related Content

Recently uploaded

Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)
Wonjun Hwang
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)
Wonjun Hwang
 

Recently uploaded (6)

A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)A future that integrates LLMs and LAMs (Symposium)
A future that integrates LLMs and LAMs (Symposium)
 
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
Continual Active Learning for Efficient Adaptation of Machine LearningModels ...
 
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution DetectionMOODv2 : Masked Image Modeling for Out-of-Distribution Detection
MOODv2 : Masked Image Modeling for Out-of-Distribution Detection
 
Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)Console API (Kitworks Team Study 백혜인 발표자료)
Console API (Kitworks Team Study 백혜인 발표자료)
 
Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)Merge (Kitworks Team Study 이성수 발표자료 240426)
Merge (Kitworks Team Study 이성수 발표자료 240426)
 
캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차캐드앤그래픽스 2024년 5월호 목차
캐드앤그래픽스 2024년 5월호 목차
 

Featured

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 

Arc

  • 1. Auto Reference Counting (ARC) 김정문 1
  • 2. ARC 소개 1. ARC는 Xcode 4.2, iOS4, iOS5에서 사용가능 (단, iOS4에서는 Weak 지원하지 않음) 2. 컴파일 시에 자동으로 적절한 위치에 retain, release, autorelease와 같은 메모리 관리와 관련된 메소드를 추가 함. 3. 가비지 컬렉터와 유사한 기능을 제공하지만 가비지 컬렉터는 아님 2
  • 3. 새로운 Rule 1. retain, release, retainCount, autorelease 사용 불가능 2. @selector(retain), @selector(release) 사용 불가능 3. Dealloc 메소드에서 [super dealloc] 호출 X 4. id와 void* 같은 암시적 형 변환 불가능 5. NSAutorelease 사용 불가능 @autoreleasepool{} 사용 3
  • 4. 새로운 Rule 1. strong : 기본 값(묵시적) 2. weak : zeroing weak reference. 해제되면 nil이 된다. 3. unsafe_unretained : weak reference. 대상 객체가 해제되면 댕글링 포인터(dangling pointer)가 된다. 4. autoreleasing : id * 형식의 인수가 리턴 시 자동적으로 해제되도록 지정된다. 4
  • 5. Strong Reference Strong Reference 1. strong 키워드는 retain과 비슷하다. 2. 해당 클래스가 소유하는 멤버변수 3. 해당 클래스의 오브젝트가 메모리에서 해제되지 않는 한 해당 오브젝트의 strong 멤버는 절대로 메모리 상에서 해제되지 않는다. 4. IB에서 File’s Owner와 nil 파일의 최상위 객체들은 strong 5
  • 6. Strong Reference (__strong) NSString *firstName = self.textField.text; 6
  • 10. Weak Reference Weak Reference 1. weak의 경우는 assign 과 비슷하면서도 다르다. 2. weak가 붙은 property는 해당 메모리가 해제되면 자동으로 nil로 초기화 된 다. 3. 인터페이스 빌더에서 연결된 IBOutlet 등에서 주로 사용 4. strong과 반대로 weak는 해당 클래스의 소유가 아님. 10
  • 11. Weak Reference __weak NSString *weakName = self.textField.text; 11