SlideShare une entreprise Scribd logo
1  sur  12
Télécharger pour lire hors ligne
ARCを使ったら人生変わった話

               @ykuroki




12年9月13日木曜日
自己紹介
   • @ykuroki
   • Web/iOS開発
   • 趣味
       – アプリ開発・さんぽ




12年9月13日木曜日
伝えたいこと
   • メモリ管理の自動化でiOS開発も楽になっ
      てきているということ




12年9月13日木曜日
アジェンダ
   • Objective-Cのメモリ管理
   • ARCとは
   • ARCのルール
   • ハマッた点
   • まとめ



12年9月13日木曜日
Objective-Cのメモリ管理
   • 「参照カウント」(Reference Counting)
   • オブジェクトの生成から破棄までを管理




              1       2        1             0         0

   オブジェクトの生成して所有   オブジェクトの所有   オブジェクトの解放         参照されくなったので破棄
         alloc       retain        release          dealloc


12年9月13日木曜日
ARCとは
   • Automatic Referense Counting
       – 参照カウントを自動でやりますよってこと

   • X-Code 4.2以降を使用する
   • ファイル単位でARCの有効化、無効化で
      きる
       – ARC無効のライブラリをそのまま使える



12年9月13日木曜日
よくわからないコードが


                 retainしてオブ
                 ジェクト所有



  dealloc時に所
   有していたオ
   ブジェクトも
      解放
                   キモい




12年9月13日木曜日
なんということでしょう



              代入することで自動
               的に所有する



   インスタンスは自
                 シュッとしている
      動で破棄




12年9月13日木曜日
ARCのルール
   • retain, releaseをタイプする必要がない
       – 変数を代入するとretain
       – スコープを抜けるとreleaseが自動的に行われ
         る

   • 明示的にdeallocを呼び出せない
       – 非ARCのときに必須だった[super dealloc]が
         エラーになる
       – dealloc自体はあります
12年9月13日木曜日
ハマった点                        自動解放されるため、呼び出したも
                                のがすでにdeallocされている可能性
                                がある。deallocされたオブジェクト
                                にアクセスするとアプリがクラッ
                                シュする




                    操作を加えると..
                                            クラッシュ!
        Subwindow                      Subwindow




12年9月13日木曜日
まとめ
   • いいところ
       – メモリ管理を気にしなくなる
       – コードの記述量が減る
   • 心配なところ
       – autorelease/retain があるとエラーになる
       – 既存モジュールが使えない可能性が高い
         →ファイル単位でARCを無効にするなどの対応必要


12年9月13日木曜日
ありがとうございました




12年9月13日木曜日

Contenu connexe

En vedette

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 2024Search Engine Journal
 
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 summarySpeakerHub
 
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 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 Tessa Mero
 
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 IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
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 managementMindGenius
 
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...RachelPearson36
 
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...Applitools
 
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 WorkGetSmarter
 
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...DevGAMM Conference
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationErica Santiago
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellSaba Software
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming LanguageSimplilearn
 
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...Palo Alto Software
 
9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free VacationWeekdone.com
 

En vedette (20)

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...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
 
Introduction to C Programming Language
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
 
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
 
9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
 

Arcを使ったら人生変わった話

  • 1. ARCを使ったら人生変わった話 @ykuroki 12年9月13日木曜日
  • 2. 自己紹介 • @ykuroki • Web/iOS開発 • 趣味 – アプリ開発・さんぽ 12年9月13日木曜日
  • 3. 伝えたいこと • メモリ管理の自動化でiOS開発も楽になっ てきているということ 12年9月13日木曜日
  • 4. アジェンダ • Objective-Cのメモリ管理 • ARCとは • ARCのルール • ハマッた点 • まとめ 12年9月13日木曜日
  • 5. Objective-Cのメモリ管理 • 「参照カウント」(Reference Counting) • オブジェクトの生成から破棄までを管理 1 2 1 0 0 オブジェクトの生成して所有 オブジェクトの所有 オブジェクトの解放 参照されくなったので破棄 alloc retain release dealloc 12年9月13日木曜日
  • 6. ARCとは • Automatic Referense Counting – 参照カウントを自動でやりますよってこと • X-Code 4.2以降を使用する • ファイル単位でARCの有効化、無効化で きる – ARC無効のライブラリをそのまま使える 12年9月13日木曜日
  • 7. よくわからないコードが retainしてオブ ジェクト所有 dealloc時に所 有していたオ ブジェクトも 解放 キモい 12年9月13日木曜日
  • 8. なんということでしょう 代入することで自動 的に所有する インスタンスは自 シュッとしている 動で破棄 12年9月13日木曜日
  • 9. ARCのルール • retain, releaseをタイプする必要がない – 変数を代入するとretain – スコープを抜けるとreleaseが自動的に行われ る • 明示的にdeallocを呼び出せない – 非ARCのときに必須だった[super dealloc]が エラーになる – dealloc自体はあります 12年9月13日木曜日
  • 10. ハマった点 自動解放されるため、呼び出したも のがすでにdeallocされている可能性 がある。deallocされたオブジェクト にアクセスするとアプリがクラッ シュする 操作を加えると.. クラッシュ! Subwindow Subwindow 12年9月13日木曜日
  • 11. まとめ • いいところ – メモリ管理を気にしなくなる – コードの記述量が減る • 心配なところ – autorelease/retain があるとエラーになる – 既存モジュールが使えない可能性が高い →ファイル単位でARCを無効にするなどの対応必要 12年9月13日木曜日