Ask Your Question

CvVideoCamera on iOS7

asked 2013-10-22 22:25:33 -0500

VoThanhLong gravatar image

When apple update to iOS7, my application got this issue: I try to re-create an CvVideoCamera object. After several times recreate, CvVideoCamera object is created slower , slower then the application got crash by memory leak. This issue only available in iOS7. So, can anyone has meet this issue. Please give me advice to resolve this problem!. Thanks in advance!

edit retag flag offensive close merge delete


I'm also facing memory issue with iOS7.

Following the image detection, I'm calling [videoCamera stop]; when I detect an image then [videoCamera start]; if something when wrong during the retrieving image process on the main thread but the more I use stop and start function, the more my application become slow until my camera stop moving :S

Furthermore due to iOS7 I'm getting 4 warning when calling [videoCamera start] function due to deprecated method which are :

AVCaptureConnection - isVideoMinFrameDurationSupported

AVCaptureConnection - setVideoMinFrameDuration:

AVCaptureConnection - isVideoMaxFrameDurationSupported

AVCaptureConnection - setVideoMaxFrameDuration:

is something can be done for not getting CvVideoCamera slow?

nakano gravatar imagenakano ( 2013-10-24 01:27:36 -0500 )edit

Sorry, I posted this as an answer previously, but were you able to find a solution?

alex_nwu gravatar imagealex_nwu ( 2013-11-02 10:34:31 -0500 )edit

Same issue over here, currently trying to build the latest framework from source to see if that fixes the issue. Have you guys made any progress on this?

gbabic gravatar imagegbabic ( 2013-11-03 17:31:15 -0500 )edit

Same issue here..., What I have noticed while I start and stop the CVVideoCamera is that first 5times or so is fine, but there is one point where the suddenly the performance changes, I mean that it looks like is not just accumulative, if you check the CPU usage you will notice a big change from 10% or so to 99... and then the memory usage start growing quickly...

I have to say that also have tried to recreate the object and it didn't work.

I hope this information will be helpful to find where the problem is. I'll keep trying to solve it in the meantime.

mccpower gravatar imagemccpower ( 2014-01-20 11:14:20 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2014-01-20 15:27:45 -0500

bskrt gravatar image

I've been running into the same issue. I managed to fix it partially though.

I pulled the latest opencv version of github and rebuild the framework myself after editing the following: In "" edit the stop method to the following:

- (void)stop;
     NSLog(@"[Camera] video stopped");
    running = NO;

    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;

    [self.captureSession stopRunning];
    [self.captureSession release];
    self.captureSession = nil;
    self.captureVideoPreviewLayer = nil;
    self.videoCaptureConnection = nil;
    captureSessionLoaded = NO;

The only difference with the original is [self.captureSession release] which seems to "properly" clean the AVCaptureSession. Memory usage is still rising slightly on each start/stop (might even be bad memory management in the rest of my code) but not exponentially like before this fix (which resulted into a crash).

(if you're having troubles building the opencv2.framework from source, you can always have a look at a previous answer of mine.)

Hope this helps!

edit flag offensive delete link more


Thanks!, that release was the key!. I also have had some issues building the framework from source but again thanks to your answer I was able to solve it.

mccpower gravatar imagemccpower ( 2014-01-21 05:34:33 -0500 )edit

answered 2014-03-14 18:43:59 -0500

AndrewK gravatar image

updated 2014-03-28 15:30:04 -0500

I did try that solution, but it does not work for me. I tried with the last git version of OpenCV (3.0.0 - dev). Does anybody have some ideas how to solve it?

Anyway, I discovered "pause" method (which is 100% safe to memory) in the CvAbstractCamera - which is inherited by CvVideoCamera, and it does exactly the same what I wanted from "stop" method. To use it I made the class which inherits from CvVideoCamera and wrote that in the MyCvVideoCamera.h:

@interface MyCvVideoCamera : CvVideoCamera
- (void) pause;


unfortunately it does not help me at all, I need stop function but it leaks memory like crazy, solution mentioned by bskrt does not work to me

edit flag offensive delete link more

Question Tools


Asked: 2013-10-22 22:25:33 -0500

Seen: 2,246 times

Last updated: Mar 28 '14