没有合适的资源?快使用搜索试试~ 我知道了~
首页Memory_Management_Programming_Guide_for_Cocoa.pdf 英文版
Memory_Management_Programming_Guide_for_Cocoa.pdf 英文版
5星 · 超过95%的资源 需积分: 10 20 下载量 74 浏览量
更新于2023-03-03
评论 1
收藏 430KB PDF 举报
Introduction In any program you write, you must ensure that you manage resources effectively and efficiently. One such resource is your program’s memory. In an Objective-C program, you must make sure that objects you create are disposed of when you no longer need them. In a complex system, it could be difficult to determine exactly when you no longer need an object. Cocoa defines some rules and principles that help making that determination easier.
资源详情
资源评论
资源推荐
Memory Management Programming Guide
for Cocoa
Cocoa > Objective-C Language
2009-07-23
Apple Inc.
© 2009 Apple Inc.
All rights reserved.
No part of this publication may be reproduced,
stored in a retrieval system, or transmitted, in
any form or by any means, mechanical,
electronic, photocopying, recording, or
otherwise, without prior written permission of
Apple Inc., with the following exceptions: Any
person is hereby authorized to store
documentation on a single computer for
personal use only and to print copies of
documentation for personal use provided that
the documentation contains Apple’s copyright
notice.
The Apple logo is a trademark of Apple Inc.
Use of the “keyboard” Apple logo
(Option-Shift-K) for commercial purposes
without the prior written consent of Apple may
constitute trademark infringement and unfair
competition in violation of federal and state
laws.
No licenses, express or implied, are granted
with respect to any of the technology described
in this document. Apple retains all intellectual
property rights associated with the technology
described in this document. This document is
intended to assist application developers to
develop applications only for Apple-labeled
computers.
Every effort has been made to ensure that the
information in this document is accurate. Apple
is not responsible for typographical errors.
Apple Inc.
1 Infinite Loop
Cupertino, CA 95014
408-996-1010
.Mac is a registered service mark of Apple Inc.
Apple, the Apple logo, Carbon, Cocoa, Mac,
Mac OS, Objective-C, and Xcode are trademarks
of Apple Inc., registered in the United States
and other countries.
iPhone is a trademark of Apple Inc.
Simultaneously published in the United States
and Canada.
Even though Apple has reviewed this document,
APPLE MAKES NO WARRANTY OR REPRESENTATION,
EITHER EXPRESS OR IMPLIED, WITH RESPECT TO
THIS DOCUMENT, ITS QUALITY, ACCURACY,
MERCHANTABILITY, OR FITNESS FOR A PARTICULAR
PURPOSE. AS A RESULT, THIS DOCUMENT IS
PROVIDED “AS IS,” AND YOU, THE READER, ARE
ASSUMING THE ENTIRE RISK AS TO ITS QUALITY
AND ACCURACY.
IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT,
INDIRECT, SPECIAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES RESULTING FROM ANY
DEFECT OR INACCURACY IN THIS DOCUMENT, even
if advised of the possibility of such damages.
THE WARRANTY AND REMEDIES SET FORTH ABOVE
ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL
OR WRITTEN, EXPRESS OR IMPLIED. No Apple
dealer, agent, or employee is authorized to make
any modification, extension, or addition to this
warranty.
Some states do not allow the exclusion or limitation
of implied warranties or liability for incidental or
consequential damages, so the above limitation or
exclusion may not apply to you. This warranty gives
you specific legal rights, and you may also have
other rights which vary from state to state.
Contents
Introduction 7
Who Should Read This Document 7
Organization of This Document 7
Object Ownership and Disposal 9
Object Ownership Policy 9
Creating Objects Using Convenience Methods 10
Objects Returned by Reference 11
Delayed Release 11
Taking Ownership of Objects 12
Validity of Shared Objects 12
Retain Cycles 13
Weak References to Objects 14
Retain Count 15
Deallocating an Object 15
Resource Management 16
Summary 16
Practical Memory Management 17
Basics 17
Simple Examples 18
Using Accessor Methods 19
Implementing a reset method 20
Common Mistakes 20
Cases which Often Cause Confusion 21
Autorelease Pools 23
Overview of Autorelease Pools 23
Autorelease Pools in Non-AppKit Programs 24
Autorelease Pools and Threads 25
Scope of Autorelease Pools and Implications of Nested Autorelease Pools 25
Guaranteeing the Foundation Ownership Policy 26
Garbage Collection 27
Accessor Methods 29
Accessor Method Fundamentals 29
Declaring Accessor Methods 29
3
2009-07-23 | © 2009 Apple Inc. All Rights Reserved.
Implementing Accessor Methods 29
Technique 1 30
Technique 2 30
Technique 3 30
Value Objects and Copying 31
Implementing Object Copy 33
Deep Versus Shallow Copies 33
Independent Copy 34
Inheriting NSCopying from the Superclass 34
Using the “alloc, init...” Approach 35
Using NSCopyObject() 35
Copying Mutable Versus Immutable Objects 37
Memory Management of Core Foundation Objects in Cocoa 39
Using Memory Zones 41
Creating and Managing Zones 41
Allocating Memory in Zones 42
Memory Management of Nib Objects 43
Outlets 43
Mac OS X Desktop 43
iPhone 44
Top-Level Objects 44
Memory Warnings 45
Memory Management Rules 47
Document Revision History 49
4
2009-07-23 | © 2009 Apple Inc. All Rights Reserved.
Figures and Listings
Object Ownership and Disposal 9
Figure 1 An illustration of retain cycles 14
Autorelease Pools 23
Listing 1 Example of a main function for a non-AppKit program 24
Implementing Object Copy 33
Figure 1 Copying instance variables both shallowly and deeply 34
Figure 2 Initialization of the reference count during a copy 37
5
2009-07-23 | © 2009 Apple Inc. All Rights Reserved.
剩余49页未读,继续阅读
Weever
- 粉丝: 4
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- ExcelVBA中的Range和Cells用法说明.pdf
- 基于单片机的电梯控制模型设计.doc
- 主成分分析和因子分析.pptx
- 共享笔记服务系统论文.doc
- 基于数据治理体系的数据中台实践分享.pptx
- 变压器的铭牌和额定值.pptx
- 计算机网络课程设计报告--用winsock设计Ping应用程序.doc
- 高电压技术课件:第03章 液体和固体介质的电气特性.pdf
- Oracle商务智能精华介绍.pptx
- 基于单片机的输液滴速控制系统设计文档.doc
- dw考试题 5套.pdf
- 学生档案管理系统详细设计说明书.doc
- 操作系统PPT课件.pptx
- 智慧路边停车管理系统方案.pptx
- 【企业内控系列】企业内部控制之人力资源管理控制(17页).doc
- 温度传感器分类与特点.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论4