NSLog(@"before remove the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
[cameraViewController.view removeFromSuperview];
NSLog(@"after remove the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
以上代码输出:
before remove the cameraViewController's retaincount is 2
before remove the cameraViewController's retaincount is 4
问题疑惑:为什么cameraViewController的retainCount的值会从2变到4呢。
求解答:
2:问题1: 两个nslog之间没有任何代码,但是这第一个nslog的%d的值为2,第二个nslog的%d的值为3,太神奇了,不知道为什么?
NSLog(@"before remove the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
NSLog(@"after remove the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
3: 下面这段代码的执行结果很让人意外,请看
cameraViewController = nil;
cameraViewController = [[IPhoneConnectTestViewController alloc] initWithNibName:@"IPhoneConnectTestViewController" bundle:nil];
NSLog(@"after alloc the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
[cameraViewController loadCamera: (CameraDO *)obj];
NSLog(@"after loadCamera the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
self.title = camera.cameraName;
[self.view addSubview:cameraViewController.view];
NSLog(@"after addSubview the cameraViewController's retaincount is %d",[cameraViewController retainCount]);
输出结果是:
2011-11-11 16:23:53.065 vsstoo[8755:11f03] after alloc the cameraViewController's retaincount is 1
2011-11-11 16:23:53.066 vsstoo[8755:11f03] after loadCamera the cameraViewController's retaincount is 1
2011-11-11 16:23:53.070 vsstoo[8755:11f03] after addSubview the cameraViewController's retaincount is 3
2011-11-11 16:23:53:250 vsstoo[8755:11f03] socket:0x849bf80 didConnectToHost:121.205.90.83 port:30016
[swscaler @ 0x9184c00]No accelerated colorspace conversion found.
不是道为什么吗?