iphone 内存管理 学习理解
来源:互联网 发布:女娇是什么网络用语 编辑:程序博客网 时间:2024/06/02 01:27
1.if you build an object using any method whose name includes alloc, new, create, or copy, you maintain responsibility for releasing the object
2. retain 属性
@property (retain) NSArray *colors;
// Non-autorelease object. Retain count is +1 at creation
NSArray *array = [[NSArray alloc]
initWithObjects:@"Black", @"Silver", @"Gray", nil];
// Count rises to +2 via assignment to a retained property
myCar.colors = array;
3.As a rule, whenever you ask another method to create an object, it’s good programming
practice to return that object autoreleased. Doing so consistently lets you follow a simple
rule:“If I didn’t allocate it, then it was built and returned to me as an autorelease object.”
- (Car *) fetchACar
{
Car *myCar = [[Car alloc] init];
return [myCar autorelease];
}
4.
You often see this pattern of create, assign, release in iPhone development.You might use
it when assigning a newly allocated view to a view controller object. For example:
UIView *mainView = [[UIView alloc] initWithFrame:aFrame];
self.view = mainView;
[mainView release];
These three steps move the object’s retain count from +1 to +2 and back to +1.
A final count of +1 guarantees you that can use an object indefinitely.At the same
time, you’re assured that the object deallocates properly when the property is set to a new
value and release is called on its prior value.That release brings the count down from +1
to 0, and the object automatically deallocates.
5.
- (void) dealloc
{
self.make = nil;
self.model = nil;
self.colors = nil;
[salesman release];
[super dealloc];
}
- iphone 内存管理 学习理解
- ios学习--Objective C内存管理进阶(一): Iphone开发内存管理的理解
- iphone内存管理
- iPhone开发内存管理
- iphone 内存管理
- iphone 内存管理memory
- iphone self--内存管理
- iPhone 内存管理
- iPhone-内存管理
- iphone 内存管理
- iPhone 内存管理
- iPhone开发内存管理
- iphone开发 内存管理
- iPhone开发内存管理
- iPhone开发内存管理
- iphone内存管理
- iphone开发--内存管理
- iPhone开发内存管理
- Java反射机制
- video studio8显示分辨率低无法打开的问题
- 不用表格,用样式进行排版定位
- Cache As Ram
- nokia 5130格式化存储卡后恢复存储卡目录名的全过程
- iphone 内存管理 学习理解
- 鼠标悬停之放大图片的效果
- 爱问智博人
- 外贸订单管理系统在excel服务器上的实现
- 电子商务人才缺口严重,并正在扩大
- JSP 和 Servlet 中的几个编码设置
- 比特域的大段小端区别
- (转载)胡适:给1932年毕业的大学生
- Struct in List