Submit Search
Upload
iPhone, iPad アプリ開発勉強会#2
•
1 like
•
1,368 views
Hiroe Orz
Follow
iPhone, iPad アプリ開発勉強会#2 の為に作成した資料です。
Read less
Read more
Technology
Report
Share
Report
Share
1 of 44
Download now
Download to read offline
Recommended
jvmlang.daitokai 1.0.0 MinCamlJを作ってみた
jvmlang.daitokai 1.0.0 MinCamlJを作ってみた
Kazuyoshi Kamitsukasa
大規模分散システムの現在 -- Twitter
大規模分散システムの現在 -- Twitter
maruyama097
iPhone, iPad アプリ開発勉強会#3
iPhone, iPad アプリ開発勉強会#3
Hiroe Orz
アップルのテンプレートは有害と考えられる
アップルのテンプレートは有害と考えられる
Brian Gesiak
AndroidでDIxAOP
AndroidでDIxAOP
nfc research
初心者〜中級者 Android StudioによるAndroid勉強会資料(スライド)
初心者〜中級者 Android StudioによるAndroid勉強会資料(スライド)
Masafumi Terazono
Android lecture for iOS developers
Android lecture for iOS developers
Masahiro Morodomi
專訪李光耀
專訪李光耀
honan4108
Recommended
jvmlang.daitokai 1.0.0 MinCamlJを作ってみた
jvmlang.daitokai 1.0.0 MinCamlJを作ってみた
Kazuyoshi Kamitsukasa
大規模分散システムの現在 -- Twitter
大規模分散システムの現在 -- Twitter
maruyama097
iPhone, iPad アプリ開発勉強会#3
iPhone, iPad アプリ開発勉強会#3
Hiroe Orz
アップルのテンプレートは有害と考えられる
アップルのテンプレートは有害と考えられる
Brian Gesiak
AndroidでDIxAOP
AndroidでDIxAOP
nfc research
初心者〜中級者 Android StudioによるAndroid勉強会資料(スライド)
初心者〜中級者 Android StudioによるAndroid勉強会資料(スライド)
Masafumi Terazono
Android lecture for iOS developers
Android lecture for iOS developers
Masahiro Morodomi
專訪李光耀
專訪李光耀
honan4108
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
Sadaomi Nishi
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
瑛一 西口
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
atsushi061452
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
Toru Tamaki
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
Toru Tamaki
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
Ayachika Kitazaki
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
atsushi061452
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
Akihiro Kadohata
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
keikoitakurag
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
Satoshi Makita
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
ssuserbefd24
Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
iwashiira2ctf
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
More Related Content
Recently uploaded
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
Sadaomi Nishi
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
瑛一 西口
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
atsushi061452
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
Toru Tamaki
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
Toru Tamaki
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
Ayachika Kitazaki
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
atsushi061452
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
Akihiro Kadohata
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
keikoitakurag
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
Satoshi Makita
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
ssuserbefd24
Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
iwashiira2ctf
Recently uploaded
(12)
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
部内勉強会(IT用語ざっくり学習) 実施日:2024年5月17日(金) 対象者:営業部社員
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
5/22 第23回 Customer系エンジニア座談会のスライド 公開用 西口瑛一
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介: Offline Q-Learning on diverse Multi-Task data both scales and generalizes
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:ViTPose: Simple Vision Transformer Baselines for Human Pose Estimation
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
論文紹介:Deep Occlusion-Aware Instance Segmentation With Overlapping BiLayers
20240523_IoTLT_vol111_kitazaki_v1___.pdf
20240523_IoTLT_vol111_kitazaki_v1___.pdf
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
論文紹介: Exploiting semantic segmentation to boost reinforcement learning in vid...
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
クラウド時代におけるSREとUPWARDの取組ーUPWARD株式会社 CTO門畑
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
Amazon Cognitoで実装するパスキー (Security-JAWS【第33回】 勉強会)
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
ロボットマニピュレーションの作業・動作計画 / rosjp_planning_for_robotic_manipulation_20240521
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
2024年5月25日Serverless Meetup大阪 アプリケーションをどこで動かすべきなのか.pptx
Intranet Development v1.0 (TSG LIVE! 12 LT )
Intranet Development v1.0 (TSG LIVE! 12 LT )
Featured
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
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
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 Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
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
Featured
(20)
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO 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)
How 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 Insights
Trends 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 summary
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
Google'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
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The 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...
iPhone, iPad アプリ開発勉強会#2
1.
iPhone, iPad
アプリ開発勉強会#2 12年12月7日金曜日
2.
一般的なアプリの構成
画面ひとつ分の構成 実行 通常は画面1つにつき、 ビュー (MyViewController.xib) •ビュー •ヘッダファイル @interface @imprementation MyViewController { •実装ファイル MyViewController { @private @synthesize *mView NSString *str - (id) init { } self = [super init]; で構成されます @prototyp(non... return self: } @end @end ヘッダファイル 実装ファイル (MyViewController.h) (MyViewController.m) 12年12月7日金曜日
3.
一般的なアプリの構成
ビューが1つのとき それ以外では、アプリひとつにつき、 アプリケーションデリゲートが1つあ ります。 実行 ビュー アプリケーションデリゲート (MyViewController.xib) @interface @imprementation @imprementation @interface MyViewController { MyViewController { MyViewController { MyViewController { @private @synthesize *mView @synthesize *mView @private NSString *str NSString *str } - (id) init { - (id) init { } self = [super init]; self = [super init]; @prototyp(non... return self: return self: @prototyp(non... } } @end @end @end @end ヘッダファイル 実装ファイル ヘッダファイル 実装ファイル (MyViewController.h) (MyViewController.m) (MyAppViewDelegate.h) (MyAppDelegate.m) 12年12月7日金曜日
4.
一般的なアプリの構成
ビューが2つのとき 実 ビュー アプリケーションデリゲートはアプリ全体で共有します @interfa @impre ce mentatio MyView n MyView ヘッダファイル 実装ファイル アプリケーションデリゲート @interface @imprementation 実 MyViewController { @private MyViewController { @synthesize *mView NSString *str ビュー } - (id) init { self = [super init]; @prototyp(non... return self: } @interfa @impre @end ce mentatio @end MyView n MyView ヘッダファイル 実装ファイル ヘッダファイル 実装ファイル (MyAppViewDelegate.h) (MyAppDelegate.m) 12年12月7日金曜日
5.
一般的なアプリの構成
なんらかの機能を提供するクラス 実 @interfa ce @impre mentatio MyView n ビュー MyView ヘッダファイル 実装ファイル @interfa @impre ce mentatio MyView n MyView ヘッダファイル 実装ファイル アプリケーションデリゲート @interface @imprementation 実 MyViewController { @private MyViewController { @synthesize *mView NSString *str ビュー } - (id) init { self = [super init]; @prototyp(non... return self: } @interfa @impre @end ce mentatio @end MyView n MyView ヘッダファイル 実装ファイル ヘッダファイル 実装ファイル (MyAppViewDelegate.h) (MyAppDelegate.m) 12年12月7日金曜日
6.
一般的なアプリ開発の流れ
1. XCodeでプロジェクト作成 2. ビューに部品(ボタン、テキストフィールド等...)を追加 3. ビューコントローラのヘッダファイルに@property(IBoutlet)宣言を追加 4. 実装ファイルに@synthesize宣言を追加 5. ビューのデザイン画面で、さきほど宣言したビューコントローラのプロパティと 実際の部品を繋ぐ。 6. コード中でビューの部品にアクセスする際には@property宣言した変数を通し て。 7. ボタンなどを配置してタップした時のアクションを定義する(次ページ) 12年12月7日金曜日
7.
一般的なアプリ開発の流れ
(アクションの定義) 1. デザイン画面にアクションを起こすボタンなどを配置する。 2. ビューコントローラのヘッダファイルにアクションのメソッド定義をする。 3. ビューコントローラの実装ファイルにアクションを実装する。 4. デザイン画面で、アクションと実際の部品を繋ぐ。 5. ボタンなどを配置して、そのボタンをタップした時のアクションのコードを書く。 6. コンパイル、動作を確認。 12年12月7日金曜日
8.
メモリ管理
Rubyと同様に、Objective-Cにおいてもクラスからインスタンスを作って使用します。 Rubyの場合 Objective-Cの場合 obj = Hoge.new Hoge *obj = [[Hoge alloc] init]; obj.sayhello #メソッド呼び出し [obj sayhello] /* メソッド呼び出し */ [obj release]; /* メモリを解放 */ /* または */ [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
9.
もしメモリを解放しないと...
アプリが使用中 10% 空きメモリ 90% 30% 5% 70% だんだんメモリ使用量が 増えていって... 40% 95% 60% iPhoneの持ってるメモリを 使い果たしてしまう! 40% 60% 実際にはそうなる前にiOS によりアプリが強制終了 されます。 12年12月7日金曜日
10.
メモリ解放するには、プログラム中で生成したオブジェクトを解放します。
オブジェクトは、誰にも使用されなくなったら解放します。 オブジェクトC オブジェクトA Hogeクラスのオブジェクト [[Hoge alloc] init] オブジェクトB オブジェクトが使われている(参照されている)状態 12年12月7日金曜日
11.
メモリ解放するには、プログラム中で生成したオブジェクトを解放します。
オブジェクトは、誰にも使用されなくなったら解放します。 オブジェクトC オブジェクトA Hogeクラスのオブジェクト オブジェクトB オブジェクトが使われていない(参照されていない)状態 こうなったら解放しちゃってもいい 12年12月7日金曜日
12.
でも、他のオブジェクトから使われているかどうかなんて、
どうやったらわかるのでしょう... 12年12月7日金曜日
13.
Objective-Cでのメモリ管理にはリファレンスカウンタを使用します
リファレンスカウンタ オブジェクトC オブジェクトA 3 Hogeクラスのオブジェクト オブジェクトB オブジェクトが使われている(参照されている)状態 12年12月7日金曜日
14.
Objective-Cでのメモリ管理にはリファレンスカウンタを使用します
リファレンスカウンタ オブジェクトC オブジェクトA 2 Hogeクラスのオブジェクト オブジェクトB オブジェクトが使われている(参照されている)状態 12年12月7日金曜日
15.
Objective-Cでのメモリ管理にはリファレンスカウンタを使用します
リファレンスカウンタ オブジェクトC オブジェクトA 1 Hogeクラスのオブジェクト オブジェクトB オブジェクトが使われている(参照されている)状態 12年12月7日金曜日
16.
Objective-Cでのメモリ管理にはリファレンスカウンタを使用します
リファレンスカウンタ オブジェクトC オブジェクトA 0 Hogeクラスのオブジェクト オブジェクトB 誰からも使われなくなったオブジェクトはリファレンスカウンタが0に! 12年12月7日金曜日
17.
Objective-Cでのメモリ管理にはリファレンスカウンタを使用します
リファレンスカウンタ オブジェクトC オブジェクトA 0 Hogeクラスのオブジェクト オブジェクトB オブジェクトは解放されてなくなりました! リファレンスカウンタが0になったときの オブジェクトの解放はiOSにより自動的に行われます。 12年12月7日金曜日
18.
実際のコードでみてみると... オブジェクトが生成された時点で、生成も
リファレンスカウンタ とのオブジェクトの参照分、1がリファレ ンスカウンタにセットされます。 1 Hoge *obj = [[Hoge alloc] init]; Hogeクラスのオブジェクト [obj sayhello] /* メソッド呼び出し */ [obj release]; /* メモリを解放 */ /* または */ [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
19.
実際のコードでみてみると... オブジェクトが生成された時点で、生成も
リファレンスカウンタ とのオブジェクトの参照分、1がリファレ ンスカウンタにセットされます。 0 Hoge *obj = [[Hoge alloc] init]; Hogeクラスのオブジェクト [obj sayhello] /* メソッド呼び出し */ [obj release]; /* メモリを解放 */ /* または */ オブジェクトに対してreleaseメソッドを呼ぶ事 でリファレンスカウンタの値が1引かれます。 [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
20.
実際のコードでみてみると...
リファレンスカウンタ 0 Hoge *obj = [[Hoge alloc] init]; Hogeクラスのオブジェクト [obj sayhello] /* メソッド呼び出し */ [obj release]; /* メモリを解放 */ /* または */ オブジェクトに対してreleaseメソッドを呼ぶ事 でリファレンスカウンタの値が1引かれます。 [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
21.
複数のオブジェクトから参照されてると...
Hoge *obj = [[Hoge alloc] init]; /* この時点でリファレンスカウンタは1 */ a.obj = obj; /* この時点でリファレンスカウンタは2 */ b.obj = obj; /* この時点でリファレンスカウンタは3 */ c.obj = obj; /* この時点でリファレンスカウンタは4 */ [obj release]; /* ここで-1されて3 */ .... /* aが解放される時にaがobjに対してreleaseを実行してカウンタは2に */ /* bが解放される時にbがobjに対してreleaseを実行してカウンタは1に */ /* cが解放される時にcがobjに対してreleaseを実行してカウンタは0に */ /* ここでオブジェクトは解放される */ 12年12月7日金曜日
22.
自動解放プールを使う方法
0 Hoge *obj = [[Hoge alloc] init]; Hogeクラスのオブジェクト [obj sayhello] /* メソッド呼び出し */ // [obj release]; /* メモリを解放 */ /* または */ [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
23.
自動解放プールを使う方法
0 Hoge *obj = [[Hoge alloc] init]; Hogeクラスのオブジェクト [obj sayhello] /* メソッド呼び出し */ // [obj release]; /* メモリを解放 */ /* または */ [obj autorelease]; /* これもメモリ解放 */ 12年12月7日金曜日
24.
releaseとautorelease(自動解放プール)の違いは...? 12年12月7日金曜日
25.
releaseを使うと、カウンタはすぐに-1され、
0になった時点でオブジェクト(の使用するメモリは)即時解放されます。 リファレンスカウンタ オブジェクトC オブジェクトA release 3 release Hogeクラスのオブジェクト release オブジェクトB 12年12月7日金曜日
26.
releaseを使うと、カウンタはすぐに-1され、
0になった時点でオブジェクト(の使用するメモリは)即時解放されます。 リファレンスカウンタ オブジェクトC オブジェクトA 0 Hogeクラスのオブジェクト オブジェクトB オブジェクトは解放されてなくなりました! リファレンスカウンタが0になったときの オブジェクトの解放はiOSにより自動的に行われます。 12年12月7日金曜日
27.
autoreleaseを使うと、カウンタはすぐには-1されず、
従ってオブジェクト(が使用するメモリ)はすぐには解放されません。 リファレンスカウンタ オブジェクトC オブジェクトA autorelease 3 autorelease Hogeクラスのオブジェクト オブジェクトB autorelease 12年12月7日金曜日
28.
そのかわり、メモ用紙(自動解放プール)にその旨を記録しておきます。
オブジェクトC 自動解放プール オブジェクトA autorelease autorelease オブジェクトAが解放した。 3 オブジェクトBが解放した。 オブジェクトCが解放した。 Hogeクラスのオブジェクト メモ用紙(自動解放プール)に記録しておく オブジェクトB autorelease 12年12月7日金曜日
29.
autoreleaseを使うと、カウンタはすぐには-1されず、
従ってオブジェクト(が使用するメモリ)はすぐには解放されません。 オブジェクトC 自動解放プール オブジェクトA オブジェクトAが解放した。 3 0 オブジェクトBが解放した。 オブジェクトCが解放した。 Hogeクラスのオブジェクト オブジェクトB 自動解放プールが解放される時に メモされている「解放」が一斉に行われます。 12年12月7日金曜日
30.
autoreleaseを使うと、カウンタはすぐには-1されず、
従ってオブジェクト(が使用するメモリ)はすぐには解放されません。 オブジェクトC 自動解放プール オブジェクトA オブジェクトAが解放した。 0 オブジェクトBが解放した。 オブジェクトCが解放した。 Hogeクラスのオブジェクト オブジェクトB 自動解放プールが解放される時に メモされている「解放」が一斉に行われます。 12年12月7日金曜日
31.
autoreleaseを使うと、カウンタはすぐには-1されず、
従ってオブジェクト(が使用するメモリ)はすぐには解放されません。 オブジェクトC 自動解放プール オブジェクトA オブジェクトAが解放した。 0 オブジェクトAが解放した。 オブジェクトAが解放した。 Hogeクラスのオブジェクト オブジェクトB 自動解放プールも開放されます... 12年12月7日金曜日
32.
どう使い分ければ... 12年12月7日金曜日
33.
どう使い分ければ...
メソッドの中でだけ使う、一時的なオブジェクトはメソッドから抜ける前に releaseで解放します。 - (void) hoge { NSArray * array = [[NSArray alloc] init]; /* 何か処理*/ [array release]; } 12年12月7日金曜日
34.
どう使い分ければ... メソッドの返り値として呼び出し元に返す値は、相手が受け取る前に解放してしまっては
まずいので、autoreleaseを使います。 - (NSArray *) hoge { NSArray * array = [[NSArray alloc] init]; [array autorelease]; /* 何か処理*/ return array; } 12年12月7日金曜日
35.
どう使い分ければ...
なお、次に説明するコンビニエンスコンストラクタを使えば なにもしなくてもautoreleaseを呼び出し済みのオブジェクトが得られます。 - (NSArray *) hoge { NSArray * array = [NSArray array]; /* 何か処理*/ return array; } 12年12月7日金曜日
36.
ちなみに、最も基本的なオブジェクト生成は
[[クラス名 alloc] init]; で、この場合はreleaseまたはautoreleaseを明示的に呼んで解放してやる必要があります。 ただし、これとは別に [クラス名 小文字ではじまるクラス名~]; というオブジェクト生成方法もあり、この場合は既にautoreleaseが呼ばれた状態で オブジェクトが渡されます。 つまり... NSArray *array = [NSArray array]; は NSArray * array = [[NSArray alloc] init] [array autorelease]; と同じです。 12年12月7日金曜日
37.
ARC (オート・レファレンス・カウンタ)とは 12年12月7日金曜日
38.
iOS5から、ARCが使えるようになりました 12年12月7日金曜日
39.
ARCを使ってもオブジェクトの解放に関する考え方は変わりませんが... 12年12月7日金曜日
40.
ARC無しの場合 -
(void) hoge { NSArray * array = [[NSArray alloc] init]; /* 何か処理*/ [array release]; } 使い終わったらreleaseしてやらないとメモリリーク! 12年12月7日金曜日
41.
ARCが有効の場合
- (void) hoge { NSArray * array = [[NSArray alloc] init]; /* 何か処理*/ } コンパイル と書いておけば... - (void) hoge { NSArray * array = [[NSArray alloc] init]; /* 何か処理*/ コンパイル時にコンパイラが勝手に追加してくれます! [array release]; } メモリにも開発者にも優しい(*´∀`*) 12年12月7日金曜日
42.
今後はARCを有効にしておいて、[[クラス alloc] init]
でオブジェクトを 生成しても解放忘れがなく、 かつARCによって自動挿入されたreleaseにより、 すぐにオブジェクトを解放してくれるのでこっちがいいかも。 12年12月7日金曜日
43.
RubyやJavaのGCとの違いは?
GC(ガベージコレクション)はアプリ実行時に一定期間おきに メモリの掃除をします。 ARCは、コンパイル時にメモリの解放コードを自動挿入し、 実行時には自動的に何かをする事はありません。 ↓ GCが走らない分、処理が止まったりせず、より滑らかでスムーズな使用感が得られます! 12年12月7日金曜日
44.
おわり 12年12月7日金曜日
Download now