Chinaunix首页 | 论坛 | 博客
  • 博客访问: 696449
  • 博文数量: 260
  • 博客积分: 7033
  • 博客等级: 少将
  • 技术积分: 2633
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-13 23:15
文章分类

全部博文(260)

文章存档

2012年(2)

2011年(41)

2010年(78)

2009年(139)

我的朋友

分类: 嵌入式

2011-07-10 01:05:39


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 



阅读(881) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~