最后一个池对象离开显示器的位置,或者我的代码中的错误/异常是什么?

时间:2011-07-29 07:13:32

标签: objective-c


#import <Foundation/Foundation.h>
#import "REFERENCE.h"
int main (int argc, const char * argv[]) 
{
    //POOL CREATION DEPARTMENT
    NSLog(@"\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tPOOL CREATION DEPARTMENT");
    NSAutoreleasePool *p=[[NSAutoreleasePool alloc] init],
    *p1=[[NSAutoreleasePool alloc] init],*p2=[[NSAutoreleasePool alloc] init],
    *p3=[[NSAutoreleasePool alloc] init],*p4=[[NSAutoreleasePool alloc] init];
    NSLog(@"\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tRC=%d of p=%@\n\n",[p retainCount],p);
    NSLog(@"RC=%d of p1=%@\n\n",[p1 retainCount],p1);
    NSLog(@"RC=%d of p2=%@\n\n",[p2 retainCount],p2);
    NSLog(@"RC=%d of p3=%@\n\n",[p3 retainCount],p3);
    NSLog(@"RC=%d of p4=%@\n\n",[p4 retainCount],p4);

    //OBJECT CREATION DEPARTMENT
    NSLog(@"\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tOBJECT CREATION DEPARTMENT\n\n");
     REFERENCE *rc=[[REFERENCE alloc] init],
    *rc1=[[REFERENCE alloc] init],*rc2=[[REFERENCE alloc] init],
    *rc3=[[REFERENCE alloc] init],*rc4=[[REFERENCE alloc] init];

        [rc autorelease];[rc1 autorelease];[rc2 autorelease];
        [rc3 autorelease];[rc4 autorelease];

    //DELETING DEPARTMENT
    NSLog(@"\n\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDELETION DEPARTMENT");
    [p1 release];
    NSLog(@"\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tRC=%d of p=%@\n\n",[p retainCount],p);
    NSLog(@"RC=%d of p1=%@\n\n",[p1 retainCount],p1);
    NSLog(@"RC=%d of p2=%@\n\n",[p2 retainCount],p2);
    NSLog(@"RC=%d of p3=%@\n\n",[p3 retainCount],p3);
    NSLog(@"RC=%d of p4=%@\n\n",[p4 retainCount],p4);

    return 0;
}

O / P是,

  

[会议开始于2011-07-29 12:27:11 +0530。] 2011-07-29   12:27:11.125 memo-mgt-referencecounter-obj-c [2529:10b]

     

POOL CREATION DEPARTMENT

     

2011-07-29 12:27:11.127 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1 = p =

     

2011-07-29 12:27:11.128 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p1 =

     

2011-07-29 12:27:11.129 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p2 =

     

2011-07-29 12:27:11.129 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p3 =

     

2011-07-29 12:27:11.130 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p4 =

     

2011-07-29 12:27:11.130 memo-mgt-referencecounter-obj-c [2529:10b]   对象创作部门

     

2011-07-29 12:27:11.131 memo-mgt-referencecounter-obj-c [2529:10b]   启动课程参考.......... RETAIN COUNT = 1   OBJECT1 =

     

2011-07-29 12:27:11.132 memo-mgt-referencecounter-obj-c [2529:10b]   启动课程参考.......... RETAIN COUNT = 1   Object2的=

     

2011-07-29 12:27:11.132 memo-mgt-referencecounter-obj-c [2529:10b]   启动课程参考.......... RETAIN COUNT = 1   OBJECT3 =

     

2011-07-29 12:27:11.133 memo-mgt-referencecounter-obj-c [2529:10b]   启动课程参考.......... RETAIN COUNT = 1   OBJECT4 =

     

2011-07-29 12:27:11.134 memo-mgt-referencecounter-obj-c [2529:10b]   启动课程参考.......... RETAIN COUNT = 1   OBJECT5 =

     

2011-07-29 12:27:11.145 memo-mgt-referencecounter-obj-c [2529:10b]   删除部门

     

2011-07-29 12:27:11.145 memo-mgt-referencecounter-obj-c [2529:10b]   拆除类别参考..........保留计数    到0并且对象仍为4

     

2011-07-29 12:27:11.146 memo-mgt-referencecounter-obj-c [2529:10b]   拆除类别参考..........保留计数    到0并且对象保持3

     

2011-07-29 12:27:11.147 memo-mgt-referencecounter-obj-c [2529:10b]   拆除类别参考..........保留计数    到0并且对象保持2

     

2011-07-29 12:27:11.148 memo-mgt-referencecounter-obj-c [2529:10b]   拆除类别参考..........保留计数    到0并且对象保持为1

     

2011-07-29 12:27:11.149 memo-mgt-referencecounter-obj-c [2529:10b]   拆除类别参考..........保留计数    到0并且对象保持为0

     

2011-07-29 12:27:11.149 memo-mgt-referencecounter-obj-c [2529:10b]                                                 RC = 1 = p =

     

2011-07-29 12:27:11.150 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p1 =

     

2011-07-29 12:27:11.151 memo-mgt-referencecounter-obj-c [2529:10b]   RC = 1的p2 =

     

2011-07-29 12:36:29.419 memo-mgt-referencecounter-obj-c [2583:10b]   RC = 1的p3 =

     

sharedlibrary apply-load-rules all附加到进程2583。

在[p1 / p2 / p3 / p4 release]等其他情况下; O / P的最后一行是 -

  

2011-07-29 12:40:38.124 memo-mgt-referencecounter-obj-c [2623:10b]   RC = 1 = p =

     

2011-07-29 12:40:38.124 memo-mgt-referencecounter-obj-c [2623:10b]   RC = 1的p1 =

     

2011-07-29 12:40:38.124 memo-mgt-referencecounter-obj-c [2623:10b]   RC = 1的p2 =

     

2011-07-29 12:40:38.125 memo-mgt-referencecounter-obj-c [2623:10b]   RC = 1的p3 =

     

2011-07-29 12:40:38.125 memo-mgt-referencecounter-obj-c [2623:10b]   RC = 1的p4 =

     

调试器已退出,状态为0。

现在我的问题是p4池在[p release]的情况下去了哪里; 这个

背后的架构是什么?

1 个答案:

答案 0 :(得分:1)

retainCount没用。不要打电话。

对于自动释放池,它们不是任何类型的标准行为对象。不能是子类,不要表现得像其他任何东西。无法反省。

文档和内存管理概念指南涵盖了所有这些内容。


您没有看到日志记录输出并不表示任何变量或池或其他任何内容都消失了。它只是意味着程序在写入日志行之前崩溃/退出