【发布时间】:2013-12-03 22:35:28
【问题描述】:
我有一个 UIViewController,我在 init 方法上设置了一个 AVCaptureVideoPreviewLayer 来拍照。拍摄照片时,我关闭 UIViewController。
每次我打开这个 UIViewController 时,Ipad 的运行速度都会变慢,直到崩溃。我收到内存警告,所以我认为它不是免费的,另一方面,我使用的是 ARC,所以我认为每次关闭 UIViewController 时它都会释放内存。
下面是 UIViewController 的 init 方法的代码:
session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
captureVideoPreviewLayer.affineTransform = CGAffineTransformMakeRotation(M_PI+M_PI_2);
captureVideoPreviewLayer.frame = CGRectMake(45, 55, 512, 387);
[self.cameraPlace.layer addSublayer:captureVideoPreviewLayer];
NSArray *cameras=[AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
AVCaptureDevice *device = [cameras objectAtIndex:1];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
[session addInput:input];
stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
NSDictionary *outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys: AVVideoCodecJPEG, AVVideoCodecKey, nil];
[stillImageOutput setOutputSettings:outputSettings];
[session addOutput:stillImageOutput];
[session startRunning];
我有什么问题吗?或者你有什么线索吗?
【问题讨论】:
-
你是如何创建 VC 的?你有财产吗?你每次都创建一个新的 VC 吗?
-
您在 VC 中时是否收到内存警告?如果打开一次会怎样?
-
每次我需要拍照时,我都会创建一个 ViewController:CameraViewController *camera = [[CameraViewController alloc] initWithBlackboard:self.farm mode:3];
-
我在 ViewController 打开时收到内存警告,如果我只打开一次 ViewController 一切正常
-
您是否添加了一些对您的 VC 的引用?听起来 VC 没有被释放。
标签: ios ios6 uiviewcontroller avcapturesession