没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Pro
Multithreading and
Memory Management
for iOS and OS X
with ARC, Grand Central Dispatch, and Blocks
Pro
COMPANION eBOOK
Shelve in:
Mobile Computing
User level:
Intermediate–Advanced
www.apress.com
BOOKS FOR PROFESSIONALS BY PROFESSIONALS
®
L
earn the technologies that are essential to develop on iOS 5 and
OS X Lion with Pro Multithreading and Memory Management for iOS
and OS X. This book takes the mystery out of multithreading and guides
you through Automatic Reference Counting (ARC) and Grand Central
Dispatch (GCD). It gives you the knowledge and skills you need to devel-
op highly responsive iOS and OS X applications with concurrency.
Pro Multithreading and Memory Management for iOS and OS X shows you
how ARC, Apple’s game-changing memory management system, works
and how best to incorporate it into your applications. You’ll also discov-
er best practices for using GCD and blocks, two key components when
controlling concurrency and memory. Key highlights include:
•
Details about how and when to use GCD
•
What blocks are and how they’re used with GCD
•
Multithreading with GCD
•
ARC technology and how to use it
•
How to manage objects with ARC
Turn to Pro Multithreading and Memory Management for iOS and OS X and
become a master iOS and OS X developer!
Gain insight into Xcode’s memory
and thread management
Companion
eBook
Available
SOURCE CODE ONLINE
Sakamoto
Furumoto
Pro
Multithreading and Memory Management for iOS and OS X
Kazuki Sakamoto | Tomohiko Furumoto
RELATED TITLES
For your convenience Apress has placed some of the front
matter material after the index. Please use the Bookmarks
and Contents at a Glance links to access them.
iii
Contents at a Glance
Contents ............................................................................................................. iv
About the Author .............................................................................................. viii
About the Translator .......................................................................................... ix
About the Technical Reviewers .......................................................................... x
Acknowledgments ............................................................................................. xi
Introduction ...................................................................................................... xii
■Chapter 1: Life Before Automatic Reference Counting .................................... 1
■Chapter 2: ARC Rules ..................................................................................... 31
■Chapter 3: ARC Implementation .................................................................... 67
■Chapter 4: Getting Started with Blocks ........................................................ 81
■Chapter 5: Blocks Implementation ................................................................ 93
■Chapter 6: Grand Central Dispatch .............................................................. 139
■Chapter 7: GCD Basics ................................................................................. 147
■Chapter 8: GCD Implementation .................................................................. 173
■Appendix A: Example of ARC, Blocks, and GCD .......................................... 181
■Appendix B: References ............................................................................... 187
Index ............................................................................................................... 193
1
Chapter
Life Before Automatic
Reference Counting
OSX Lion and iOS5 now offer an application memory management mechanism called
Automatic Reference Counting (ARC). In short, ARC makes memory management the
job of the compiler rather than the programmer, which quite often increases
performance significantly.
In Chapters 2 and 3, you see just how powerful ARC is. But before entering such a
dream world, it’s best to review the basics of memory management in a non-ARC
environment. In doing so, you’ll form a greater appreciation of all that ARC has to offer
and build a stronger foundation for when we delve into ARC in the next two chapters.
We start with an overview of memory management and its concepts followed by the
implementation of features such as alloc, dealloc, and autorelease.
Reference Counted Memory Management Overview
In many cases in Objective-C, we can rephrase "memory management" as "reference
counting." Memory management means that a programmer allocates a memory area
when the program needs it and frees it when the program no longer needs it. Unneeded
memory areas that are not freed properly are a waste of resources. Also it may crash the
application. Reference counting, invented by George E. Collins in 1960, is used to make
memory management simple.
To illustrate what reference counting is let’s use the following light in an office analogy
(Figure 1–1).
1
CHAPTER 1: Life Before Automatic Reference Counting
2
Figure 1–1. A lamp in an office
Imagine that there is only one light in an office. In the morning, when someone comes
into the office, he turns on the light because he needs it. When he leaves the office, he
does not need it anymore so he turns it off. What will happen if more than one person
turns it on and off when they move in and out? Whenever he leaves, he just turns off the
light, which means it becomes dark even though others still work there (Figure 1–2).
Figure 1–2. Problem of light
To solve this problem, we need some rules to ensure that the light is on when one or
more person is there and off only when no one is there.
1. When someone comes into an empty office, she turns on the light.
2. Any following people entering the room use the light as well.
3. When someone leaves, that person no longer needs the light.
4. When the last person leaves, he turns the light off.
l
剩余205页未读,继续阅读
ffwmxr
- 粉丝: 12
- 资源: 70
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页