Mat leaking memory using Canny
I'm doing live video processing on iOS using OpenCV, without using CvVideoCamera
. My app is crashing due to Memory Pressure.
The native iOS camera calls this function every time a frame is captured:
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
{
//convert the frame to a UIImage:
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
//convert the UIImage to a Mat:
Mat srcMat = [self cvMatFromUIImage:image];
//Process the Mat:
Mat dst, cdst;
Canny(srcMat, dst, 50, 200, 3);
cvtColor(dst, cdst, COLOR_GRAY2BGR);
}
The app crashes about 15 seconds later due to memory pressure.
After some investigation, I found that the call to Canny()
is responsible, but I can't figure out why...
It looks like the Mat
objects are staying in memory, but aren't Mat
objects released automatically?