iOS5中使用了Objective-C Automatic Reference Counting 自动引用计数机制,在编程中不需要我们主动retain/release/autorelease一个对象了。
MyClass的dealloc中打印了 NSLog(@"%s %d", __FUNCTION__, __LINE__);
在AppDelegateDidFinishLaunching中做如下处理:
NSLog(@"before 1");
{
static MyClass *m = nil;
m = [[MyClass alloc] init]; // m没有被销毁,所指向对象也没有被销毁
}
NSLog(@"after 1");
NSLog(@"before 2");
{
MyClass *m = nil;
m = [[MyClass alloc] init]; // m被销毁,对象同时也被销毁。
}
打印结果:
2011-07-10 00:59:44.556 aaaaa[4965:207] before
2011-07-10 00:59:44.558 aaaaa[4965:207] after
2011-07-10 00:59:44.558 aaaaa[4965:207] before
2011-07-10 00:59:44.558 aaaaa[4965:207] -[MyClass dealloc] 25
2011-07-10 00:59:44.559 aaaaa[4965:207] after
阅读(915) | 评论(0) | 转发(0) |