Skip to content

Commit

Permalink
Fixed Memory leaks when using the AVCaptureInput
Browse files Browse the repository at this point in the history
Thanks to coremjs for the finds
  • Loading branch information
nielswh committed Oct 7, 2011
1 parent 327ce92 commit f4822e0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 0 additions & 1 deletion ARKit/AugmentedRealityController.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
- (void) setupDebugPostion;
- (void) updateLocations;
- (void) stopListening;
- (void) unloadCamera;

// Adding coordinates to the underlying data model.
- (void)addCoordinate:(ARCoordinate *)coordinate augmentedView:(UIView *)agView animated:(BOOL)animated ;
Expand Down
16 changes: 13 additions & 3 deletions ARKit/AugmentedRealityController.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,19 @@ - (id)initWithViewController:(ARViewController *)vc {
return self;
}

- (IBAction)closeButtonClicked:(id)sender {
[[self rootViewController] dismissModalViewControllerAnimated:YES];
-(void)unloadAV {
[captureSession stopRunning];
AVCaptureInput* input = [captureSession.inputs objectAtIndex:0];
[captureSession removeInput:input];
[[self previewLayer] removeFromSuperlayer];
[self setCaptureSession:nil];
[self setPreviewLayer:nil];
}

-(void) unloadCamera {
- (IBAction)closeButtonClicked:(id)sender {
[self stopListening];
[self unloadAV];
[[self rootViewController] dismissModalViewControllerAnimated:YES];
}

- (void)startListening {
Expand Down Expand Up @@ -528,8 +535,11 @@ - (void)setDebugMode:(BOOL)flag {
}

- (void)dealloc {
[self unloadAV];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[ARView release];
locationManager.delegate = nil;
[UIAccelerometer sharedAccelerometer].delegate = nil;
[locationManager release];
[coordinateViews release];
[coordinates release];
Expand Down
3 changes: 2 additions & 1 deletion ARKitDemo/Classes/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ -(IBAction) displayAR:(id)sender {
[self setCameraViewController:newCameraViewController];
[newCameraViewController release];
[cameraViewController setModalTransitionStyle: UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:cameraViewController animated:YES];
[self presentModalViewController:cameraViewController animated:YES];
newCameraViewController = nil;
}
else {
UIViewController *newInfoViewController = [[UIViewController alloc] init];
Expand Down

0 comments on commit f4822e0

Please sign in to comment.